Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int mx=1e5+123;
- bool is_prime[mx];
- void prime_gen(int n)
- {
- is_prime[2]=1;
- for(int i=3;i<=n;i+=2) is_prime[i]=1;
- for(int i=3;i*i<=n;i+=2)
- {
- if(is_prime[i]==1)
- {
- for(int j=i*i;j<=n;j+=(i+i))
- {
- is_prime[j]=0;
- }
- }
- }
- }
- int main()
- {
- int lim=1e5;
- prime_gen(lim);
- int n;
- cin>>n;
- if(n==1||n==2) cout<<1<<endl;
- else{
- cout<<2<<endl;
- }
- for(int i=2;i<=n+1;i++)
- {
- if(is_prime[i]==1) cout<<1<<" ";
- else cout<<2<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement