URAL - 2070 Interesting Numbers 规律

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 ≤ 10 12).

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
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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值