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 [ L; R] 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 ≤ 10 12).
Output
In the only line output one integer — the number of satisfying integers from segment [ L; R].
Example
input | output |
---|---|
3 7 | 4 |
2 2 | 1 |
77 1010 | 924 |
题解:打表后发现不满足题意的只有可能是合数,并且他的因子个数为素数,进一步找到规律:所有不满足题意的一定是素数的某素数的减1次方,那么接下来就好办了。首先预处理标记1e6之内的所有素数,然后暴力找不符合条件的就好了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isprime[1000005];
void Prime()//标记素数
{
memset(isprime,1,sizeof(isprime));
// isprime[1]=0;
for(int i=2;i<=1000;i++)
{
for(int j=i*i;j<=1000000;j+=i)
isprime[j]=0;
}
}
int main()
{
Prime();
ll l,r,ans,i,j;//注意i一定要long long ,否则会爆~~
while(cin>>l>>r)
{
ans=r-l+1;
for(i=2;i*i<=r;i++)
{
if(isprime[i])//为素数才可以
{
ll temp=i;
for(j=3;;j++)//从方幂加1开始循环,如果区间范围内的j为素数ans就要减1
{
temp*=i;//进行方幂加1
if(temp>r)
break;
if(isprime[j]&&temp>=l)
ans--;
}
}
}
cout<<ans<<endl;
}
return 0;
}