Advertisement
momo2345

almost prime

Nov 17th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. using namespace __gnu_pbds;
  6. typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
  7. #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  8. #define endl "\n"
  9. #define mn int main()
  10. #define frac() cout.unsetf(ios::floatfield);cout.precision(6);cout.setf(ios::fixed,ios::floatfield);
  11.  
  12.  
  13. const int mx=1e8+123;
  14. bitset<mx>isprime;
  15. vector<int>prime;
  16. void primegen(int n)
  17. {
  18. for(int i=3;i<=n;i+=2) isprime[i]=1;
  19. for(int i=3;i*i<=n;i+=2){
  20. if(isprime[i]){
  21. for(int j=i*i;j<=n;j+=(i*2))
  22. isprime[j]=0;
  23. }
  24. } //O(n)
  25. isprime[2]=1;
  26. prime.push_back(2);
  27. for(int i=3;i<=n;i+=2){
  28. if (isprime[i]) prime.push_back(i);
  29. }
  30. }
  31. mn
  32. {
  33. suni;
  34.  
  35. int n; cin>>n;
  36. int ans=0,alpm=0;
  37. primegen(n);
  38. for(int i=1;i<=n;i++){
  39. for(auto u : prime){
  40. if(u>=i) break;
  41. if(i%u==0) ans++;
  42. }
  43. if(ans==2) alpm++;
  44. ans=0;
  45. }
  46. cout<<alpm<<endl;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement