H - Interesting Numbers URAL - 2070 ----素数筛+唯一分解定理

H - Interesting Numbers

  URAL - 2070 

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].
Example
input output
3 7
4
2 2
1
77 1010
924

题目链接:https://cn.vjudge.net/contest/160744#problem/H


不难的一个数论题,题目的意思是说让你求在L,R区间里,同时满足或者同事不满足素数和这个数的约数个数是素数的要求的数的个数。。有点绕。

我们先用素数筛求出1e6以内的素数,然后我们用唯一分解定理来求约数个数

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
const int maxn=1000010;
LL vis[maxn];
LL p[maxn];
int sum;
void getprime(){
    sum=1;
    for(LL i=2;i<=maxn;i++){
        if(vis[i]==0){
            p[sum++]=i;
            for(LL j=i*2;j<=maxn;j+=i){
                vis[j]=1;
            }
        }
    }
}
LL solve(LL x){
    LL ret=x;
    for(int i=1;i<sum;i++){
        LL t=(LL)p[i]*p[i];
        int k=2;
        for(;t<=x;k++,t=t*p[i]){
            if(!vis[k+1]){//判断2条件是不是满足
                ret--;//只满足一个条件
            }
        }
    }
    return ret;
}
int main(){
    getprime();
    LL L,R;
    while(~scanf("%lld%lld",&L,&R)){
        LL ans=solve(R)-solve(L-1);
        cout<<ans<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值