标签:
//
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "algorithm" 5 using namespace std; 6 const int maxn = 10000100; 7 int tot, pr[maxn]; 8 bool is_pr[maxn]; 9 int n, m, l, r, cnt[maxn], sum[maxn]; 10 11 int main() 12 { 13 int i, j, ans; 14 scanf("%d", &n); 15 for(i = 1; i<=n; ++i) { 16 scanf("%d", &ans); 17 ++cnt[ans]; 18 } 19 20 memset(is_pr, 1, sizeof(is_pr)); 21 for(i = 2; i < maxn; ++i) { 22 if(is_pr[i]) { 23 if(cnt[i]) 24 sum[i] += cnt[i]; 25 for(j = (i<<1); j < maxn; j += i) { 26 is_pr[j] = 0; 27 if(cnt[j]) { 28 sum[i] += cnt[j]; 29 } 30 } 31 } 32 } 33 for(i = 2; i < maxn; ++i) 34 sum[i] += sum[i-1]; 35 36 scanf("%d", &m); 37 while(m--) { 38 scanf("%d%d", &l, &r); 39 l = min(l, maxn - 1); 40 r = min(r, maxn - 1); 41 printf("%d\n", sum[r] - sum[l - 1]); 42 } 43 }
CodeForces 385C 素数朴素筛法,穷尽数的素数因子
标签:
原文地址:http://www.cnblogs.com/AC-Phoenix/p/4288761.html