ural 2070. Interesting Numbers

时间:2023-03-08 15:46:59

2070. Interesting Numbers

Time limit: 2.0 second
Memory limit: 64 MB
Nikolay and Asya investigate integers together in their spare time. Nikolay thinks an integer is interesting if it is a prime number. However, Asya thinks an integer is interesting if the amount of its positive divisors is a prime number (e.g., number 1 has one divisor and number 10 has four divisors).
Nikolay and Asya are happy when their tastes about some integer are common. On the other hand, they are really upset when their tastes differ. They call an integer satisfying if they both consider or do not consider this integer to be interesting. Nikolay and Asya are going to investigate numbers from segment [LR] this weekend. So they ask you to calculate the number of satisfying integers from this segment.

Input

In the only line there are two integers L and R (2 ≤ L ≤ R ≤ 1012).

Output

In the only line output one integer — the number of satisfying integers from segment [LR].

Samples

input output
3 7
4
2 2
1
77 1010
924
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2015
Difficulty: 221
题意:问l~r之间
1、x是个质数
2、约数个数是质数
要么满足两者,要么两者都不满足的数的个数
分析:
我们只要扣除只满足一个的数就可以了
首先1特殊处理
考虑x=p1^k1 * p2^k2 *....
当质因子超过1个,则两者都不满足
当质因子只有一个,当k==1时,两者满足
当k>1时,就要扣除
所以只用枚举质数,查看在l-r内的幂就行了
 #include <iostream>
#include <cstdio>
using namespace std; const int N = ;
typedef long long LL;
LL l, r;
LL prime[N];
int tot;
bool visit[N]; inline void input()
{
cin >> l >> r;
} inline void solve()
{
if(l == r && l == )
{
cout << "1\n";
return;
} LL ans = ;
if(l == ) l++, ans++;
for(int i = ; i < N; i++)
{
if(!visit[i]) prime[++tot] = i;
for(int j = ; j <= tot; j++)
{
if(prime[j] * i >= N) break;
visit[prime[j] * i] = ;
if(!(i % prime[j])) break;
}
} ans += r - l + ;
for(int i = ; i <= tot; i++)
{
LL now = ;
int times = ;
while(now < l) now *= prime[i], times++;
while(now <= r)
{
if(times > && !visit[times + ]) ans--;
now *= prime[i], times++;
}
} cout << ans << "\n";
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}