URAL - 2070
2016-09-05 21:13
357 查看
URAL - 2070点我点我:-)
题意:[ L , R ]区间内,既不是质数,因数个数也不为质数的数的个数
#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 < M
b8dd
AXN; 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;
}
Interesting Numbers
Status Description 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]. Sample Input
|
<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 < M
b8dd
AXN; 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;
}
相关文章推荐
- URAL 2070
- URAL 2070 Interesting Numbers (找规律)
- URAL 2070 Interesting Numbers(数学)
- URAL 2070 Interesting Numbers(数学)
- H - Interesting Numbers URAL - 2070 ----素数筛+唯一分解定理
- Interesting Numbers URAL - 2070 数论
- 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(数论基础)
- Fibbonacci Number(杭电2070)
- URAL 1167
- URAL 1731. Dill(数学啊 )
- URAL - 1004 Sightseeing Trip(最小环)
- Adventure Time URAL - 2024---多坑点的排列组合
- URAL-1101. Robot in the Field
- URAL 1011|Conductors|暴力