URAL - 2070点我点我:-)
题意:[ L , R ]区间内,既不是质数,因数个数也不为质数的数的个数
<a target=_blank href="http://acm.hust.edu.cn/vjudge/problem/261234/origin" target="_blank"><span style="font-family:Verdana;color:green;text-align:left;">
</span></a>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define MAXN (1000000+10)
LL prime[MAXN];
bool fisp[MAXN];
int tot;
void Prime(){
for(LL i = 2; i < MAXN; i++)
if(!fisp[i]){
prime[++tot] = i;
for(LL j = i+i; j < MAXN; j+=i) fisp[j] = true;
}
}
LL calc(LL now){
LL ret = now;
for(int i = 1; i <= tot; i++){
LL tmp = prime[i]*prime[i];
int k = 2;
while(tmp <= now){
if(!fisp[k+1]) ret--;
k++; tmp *= prime[i];
}
}
return ret;
}
int main(){
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
Prime();
LL L, R;
scanf("%lld%lld", &L, &R);
printf("%lld\n", calc(R)-calc(L-1));
return 0;
}