Advertisement
momo2345

sherlock

Nov 4th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 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=1e5+123;
  14. bitset<mx>isprime;
  15. vector<int>prime(mx);
  16. void primegen(int n)
  17. {
  18.     n+=100;
  19.     for(int i=3;i<=n;i+=2) isprime[i]=1;
  20.     for(int i=3;i*i<=n;i+=2){
  21.             if(isprime[i]){
  22.         for(int j=i*i;j<=n;j+=(i*2))
  23.             isprime[j]=0;
  24.       }
  25.     } //O(n)
  26.     isprime[2]=1;
  27.     for(int i=1;i<=n;i++){
  28.         if(isprime[i+1]) prime[i+1]=1;
  29.         else  prime[i+1]=2;
  30.     }
  31. }
  32. mn
  33. {
  34.     int n;
  35.     cin>>n;
  36.     primegen(n);
  37.     if(n<3) cout<<1<<endl;
  38.     else cout<<2<<endl;
  39.     for(int i=1;i<=n;i++)
  40.         cout<<prime[i+1]<<" ";
  41.  
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement