hkshakib

Untitled

May 7th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll maxn=1e7+5;
  5. ll freq[maxn],ans[maxn],arr[maxn];
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(NULL);
  10. ll n,m;
  11. cin>>n;
  12. for(ll i=1; i<=n; i++)
  13. {
  14. ll p;
  15. cin>>p;
  16. freq[p]++;
  17. }
  18. for(ll i=2; i<maxn; i++)
  19. {
  20. arr[i]=arr[i-1];
  21. if(ans[i])
  22. continue;
  23. arr[i]+=freq[i];
  24. for(ll j=i+i; j<maxn; j+=i)
  25. {
  26. ans[j]=1;
  27. arr[i]+=freq[j];
  28. }
  29. }
  30. cin>>m;
  31. for(ll i=1; i<=m; i++)
  32. {
  33. ll l,r;
  34. cin>>l>>r;
  35. r =min(maxn-1,r);
  36. l =min(maxn-1,l-1);
  37. cout<<arr[r]-arr[l]<<endl;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment