Saleh127

UVA 11408

Jul 26th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define maX 5000001
  7. bool marked[maX+5];
  8. ll sum[maX+5];
  9. ll ans[maX+5];
  10. void sieve()
  11. {
  12. sum[0]=0;
  13. sum[1]=0;
  14. marked[0]=0;
  15. marked[1]=0;
  16. for(ll i=2;i<=maX;i++)
  17. {
  18. if(marked[i]==0)
  19. {
  20. sum[i]=i;
  21. for(ll j=2*i;j<=maX;j+=i)
  22. {
  23. marked[j]=1;
  24. sum[j]+=i;
  25. }
  26. }
  27. }
  28. for(ll i=2;i<=maX;i++)
  29. {
  30. if(marked[i]==0 || marked[sum[i]]==0)
  31. {
  32. ans[i]=ans[i-1]+1;
  33. }
  34. else ans[i]=ans[i-1];
  35. }
  36.  
  37. }
  38. int main()
  39. {
  40. fellow_junior
  41. sieve();
  42. ll a,c,d,e,f,i,j,k,l;
  43. while(cin>>a &&a)
  44. {
  45. cin>>c;
  46. cout<<ans[c]-ans[a-1]<<endl;
  47. }
  48. return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment