标签:
题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数。
析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然后用总数减掉就好。打个表,找找规律,你会发现,
这些数除外的数都是素数的素数次方,然后就简单了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include <cmath> #include <stack> #define frer freopen("in.txt", "r", stdin) #define frew freopen("out.txt", "w", stdout) using namespace std; typedef long long LL; typedef pair<int, int> P; const int INF = 0x3f3f3f3f; const double inf = 0x3f3f3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-8; const int maxn = 1e6 + 5; const int mod = 1e8; const char *mark = "+-*"; const int dr[] = {-1, 0, 1, 0}; const int dc[] = {0, 1, 0, -1}; int n, m; const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; inline int Min(int a, int b){ return a < b ? a : b; } inline int Max(int a, int b){ return a > b ? a : b; } inline LL Min(LL a, LL b){ return a < b ? a : b; } inline LL Max(LL a, LL b){ return a > b ? a : b; } inline bool is_in(int r, int c){ return r >= 0 && r < n && c >= 0 && c < m; } int a[maxn]; vector<int> prime; int main(){ for(int i = 2; i <= sqrt(1000001+0.5); ++i) if(!a[i]){ for(int j = i * i; j <= 1000001; j += i) a[j] = 1; } for(int i = 2; i <= 1000001; ++i) if(!a[i]) prime.push_back(i); LL x, y; while(cin >> x >> y){ int cnt = 0; for(int i = 0; i < prime.size(); ++i){ LL t = (LL)prime[i] * (LL)prime[i]; int k = 2; while(t <= y){ ++k; if(!a[k] && t >= x && t <= y) ++cnt; t *= prime[i]; } } LL ans = y - x - cnt + 1; cout << ans << endl; } return 0; }
URAL 2070 Interesting Numbers (找规律)
标签:
原文地址:http://www.cnblogs.com/dwtfukgv/p/5796882.html