Saleh127

UVA 11105

Nov 29th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. vector<ll>p;
  6. bool mark[1000005];
  7. void sieve()
  8. {
  9. ll i,j;
  10. for(i=5; i<1000005; i+=4)
  11. {
  12. if(mark[i]==0)
  13. {
  14. p.push_back(i);
  15. for(j=2*i; j<1000005; j+=i)
  16. {
  17. mark[j]=1;
  18. }
  19. }
  20. }
  21. }
  22.  
  23. ll solve(ll n)
  24. {
  25. ll ans=0,i,j,k,l;
  26. memset(mark,0,sizeof(mark));
  27.  
  28. for(i=0; i<p.size() && p[i]*p[i]<=n; i++)
  29. {
  30. for(j=i; j<p.size() && p[i]*p[j]<=n; j++)
  31. {
  32. k=p[i]*p[j];
  33.  
  34. if(mark[k]==0)
  35. {
  36. ans++;
  37. mark[k]=1;
  38. }
  39. }
  40. }
  41. return ans;
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. ios_base::sync_with_stdio(0);
  48. cin.tie(0);
  49. cout.tie(0);
  50.  
  51. sieve();
  52. ll n;
  53. while(cin>>n && n)
  54. {
  55. cout<<n<<" "<<solve(n)<<endl;
  56. }
  57.  
  58. return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment