Codeforce Round #226 Div2 C
→ Practice
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.
1 #pragma comment(linker,"/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <vector> 4 #include <cmath> 5 #include <queue> 6 #include <cstring> 7 #include <iostream> 8 #include <algorithm> 9 using namespace std; 10 #define INF 0x7fffffff 11 #define mod 1000000007 12 #define ll long long 13 #define maxn 10000025 14 #define pi acos(-1.0) 15 int n, m; 16 int a[1000025], pri[1000025], prv[maxn],b[maxn]; 17 ll c[maxn]; 18 void add(int x, ll d){ 19 while (x < maxn){ 20 c[x] += d; 21 x += x&-x; 22 } 23 } 24 ll sum(ll x){ 25 ll res = 0; 26 while (x > 0){ 27 res += c[x]; 28 x -= x&-x; 29 } 30 return res; 31 } 32 int main(){ 33 for (int i = 2; i*i < maxn;i++) 34 if (!prv[i]){ 35 for (int j = i*i; j < maxn;j+=i) 36 if (!prv[j])prv[j] = 1; 37 } 38 int k = 0; 39 for (int i = 2; i < maxn;i++) 40 if (!prv[i])pri[k++] = i; 41 scanf("%d", &n); 42 for (int i = 0; i < n; i++)scanf("%d", &a[i]); 43 for (int i = 0; i < n; i++)b[a[i]]++; 44 for (int i=0;i<k;i++) 45 for (int j = pri[i]; j < maxn; j += pri[i]) 46 if(b[j])add(pri[i], b[j]); 47 scanf("%d", &m); 48 while (m--){ 49 int l, r; 50 scanf("%d%d", &l, &r); 51 if (l >= maxn){printf("0\n"); continue;} 52 if (r >= maxn)r = maxn - 1; 53 printf("%I64d\n", sum(r) - sum(l - 1)); 54 } 55 return 0; 56 }




, where
浙公网安备 33010602011771号