URAL

来源:互联网 发布:2017淘宝卖什么最赚钱 编辑:程序博客网 时间:2024/04/28 20:08

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

inputoutput
3 7
4
2 2
1
77 1010
924
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2015
Tags: number theory  (
hide tags for unsolved problems
)
http://acm.timus.ru/problem.aspx?space=1&num=2070


满意的数有两人都认为有趣的:素数

两人都认为没趣的:合数且因子数不为质数

看样例就知道这样的数很多,

不过可以求不满意的数:合数且因子数为质数

把一个数质因子分解x=p1^a1*p2^a2*p3^a3...

x的因子的个数为  (a1+1)(a2+1)(a3+1)。。。。()

上式中的每一项都是大于1的,而我们如果要求上式的结果为一个质数,很明显只能留下一项,且这一项为一个质数(即ai+1为一个质数)

那么不满意的数就是:质数的   质数减一    次方,这样他的因子肯定是质数个

#include<stdio.h>#include<algorithm>#include<string.h>#include<queue>#include<map>#include<vector>#include<math.h>using namespace std;bool prime[1000005];void getprime(){    long long int i,j;    memset(prime,0,sizeof(prime));    for(i=2;i<=1000000;i++)    {        if(!prime[i])        {            for(j=2;j*i<=1000000;j++)            {                prime[j*i]=true;            }        }    }}long long int solve(long long x){    long long ans=x,i,j,k;    for(i=2;i*i<=x;i++)    {        if(!prime[i])        {            k=i;            for(j=3;j<1000001;j++)            {                k*=i;                if(k>x)                    break;                if(!prime[j])                ans--;            }        }    }    return ans;}int main(){    getprime();    long long l,r;    scanf("%lld %lld",&l,&r);    printf("%lld\n",solve(r)-solve(l-1));    return 0;}



0 0