素数标记 Interesting Numbers URAL - 2070
2017-02-18 20:28
190 查看
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
题意:在L R区间内 求的是有多少个 他的因子个数也是素数。 比如6 因子1 2 3 6 一共4个 4不是素数 就不是满足题意的。
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 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = 1000000 + 10;
const int inf = 0x3f3f3f3f;
typedef long long ll;
vector<ll>prime;
int len_pri;
int vis[maxn];
void init(){
int len = sqrt(maxn) + 1;
for (int i = 2; i <= len; ++i)if (!vis[i])
for (int j = i+i; j <= maxn; j += i)vis[j] = 1; //把非素数全标记为1for (int i = 2; i <= maxn; ++i)if (!vis[i])prime.push_back(i);// 把素数全存在prime里面
len_pri = (int)prime.size();
}
int main(){
init();
ll l,r;
scanf("%I64d %I64d",&l,&r);
ll ans = 0;
for (int i = 0; i < len_pri; ++i){
ll cur = 1;
if (prime[i] * prime[i] > r)break;
int sum = 0;
while(cur < l)cur *= prime[i],++sum;//找的是非素数 从*自己开始找 因为素数一定符合条件 素数的因子是1和本身==2 2是素数
while(cur <= r){
if (sum > 1 && !vis[sum+1])++ans;
cur *= prime[i];
++sum;
}
}
printf("%I64d\n",r-l+1-ans);
return 0;
}
相关文章推荐
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- 素数标记 Interesting Numbers URAL - 2070
- URAL 2070 Interesting Numbers (素数枚举)
- 素数标记法求n以内所有的素数
- Light 1289 - LCM from 1 to n (位图标记+素数筛选)
- H - Interesting Numbers URAL - 2070 ----素数筛+唯一分解定理
- 筛选法求素数表,并标记素数位置和合数最大质数位置 HOJ 2136
- Largest prime factor(素数标记)
- CodeForces 154B——Colliders——筛选素数,模拟标记
- 筛选法(判断一个数是不是素数,将所有数标记,再判断)
- 利用穷举法和函数(用到标记flag)求出100--150之间的素数以及用标记求出100之内的素数