Advertisement
erfanul007

UVa 10539

Dec 27th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // #pragma GCC optimize("Ofast,no-stack-protector")
  5. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. // #pragma GCC optimize("unroll-loops")
  7.  
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. typedef long double lld;
  11. typedef vector<int> vi;
  12. typedef vector<ll> vll;
  13. typedef vector<vi> vvi;
  14. typedef pair<int,int > pii;
  15. typedef pair<ll,ll > pll;
  16. typedef vector< pii > vpii;
  17. typedef vector< pll > vpll;
  18. typedef set<int> sti;
  19.  
  20. #define sc scanf
  21. #define pf printf
  22. #define sci(n) scanf("%d",&n)
  23. #define scii(n,m) scanf("%d %d",&n,&m)
  24. #define scl(n) scanf("%lld",&n)
  25. #define scd(n) scanf("%lf",&n)
  26. #define scs(s) scanf("%s",s)
  27. #define pfi(n) printf("%d",n)
  28. #define pfl(n) printf("%lld",n)
  29. #define pff(n) cout<<n
  30. #define spc printf(" ")
  31. #define line printf("\n")
  32. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  33. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  34. #define cspf(i) printf("Case %d: ", i)
  35. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  36. #define clr(a,x) memset(a,x,sizeof(a))
  37. #define tp(v,j) get<j>(v)
  38. #define pb push_back
  39. #define mp make_pair
  40. #define mt make_tuple
  41. #define ff first
  42. #define ss second
  43. #define all(v) v.begin(),v.end()
  44. #define rall(v) v.rbegin(),v.rend()
  45. #define read() freopen("input.txt", "r", stdin)
  46. #define write() freopen("output.txt", "w", stdout)
  47. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  48. /// Constants
  49. #define eps 1e-6
  50. #define PI acos(-1.0) // 3.1415926535897932
  51. #define MAX (ll)2147483647
  52. #define MAXn (ll)1000009
  53.  
  54. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  55. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  56.  
  57. bool isprime[MAXn+1];
  58. vll prime;
  59.  
  60. void seive()
  61. {
  62. clr(isprime,true);
  63. isprime[0]=false;
  64. isprime[1]=false;
  65. for(int i=4;i<MAXn;i+=2) isprime[i]=false;
  66. for(int i=3;i*i<MAXn;i+=2){
  67. if(!isprime[i]) continue;
  68. for(int j=i*i;j<MAXn;j+=2*i) isprime[j]=false;
  69. }
  70.  
  71. prime.pb(2LL);
  72. for(int i=3;i<MAXn;i+=2){
  73. if(isprime[i]) prime.pb((ll)i);
  74. }
  75. }
  76.  
  77. int almostcnt(ll l,ll r)
  78. {
  79. int cnt=0;
  80. for(int i=0;(ll)prime[i]*prime[i]<=r;i++){
  81. int x = floor((double)log(r)/log(prime[i]));
  82. int y = floor((double)log(l)/log(prime[i]));
  83. int z = ceil((double)log(l)/log(prime[i]));
  84. //cout<<r<<' '<<x<<' '<<y<<' '<<z<<'\n';
  85. cnt+=(x-y);
  86. if(y==z && y) cnt++;
  87. if(l<=prime[i]) cnt--;
  88. }
  89. return cnt;
  90. }
  91.  
  92.  
  93. int main()
  94. {
  95. #ifdef VAMP
  96. clock_t tStart = clock();
  97. freopen("input.txt", "r", stdin);
  98. freopen("output.txt", "w", stdout);
  99. #endif
  100.  
  101. seive();
  102. //cout<<prime.size();
  103. int t;
  104. sci(t);
  105. while(t--){
  106. ll l,r;
  107. scl(l),scl(r);
  108. pfi(almostcnt(l,r));
  109. line;
  110.  
  111. }
  112.  
  113. #ifdef VAMP
  114. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  115. #endif
  116.  
  117. return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement