Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #define ll long long
- #include <bits/stdc++.h>
- int main() {
- ll int n;
- cin>>n;
- vector<ll int> lp(n+2,1);
- for(ll int i=0;i<=n+1;i++) lp[i]=i;
- vector< ll int> color(n+2,1);
- for(ll int i=2;i<=n+1;i++) {
- if(lp[i]==i) {
- for(ll int j=i*i;j<=n+1;j+=i) {
- if(lp[j]==j) lp[j]=i;
- }
- }
- }
- ll int maxI=1;
- for(ll int i=2;i<=n+1;i++) {
- if(lp[i]!=i) {
- color[i]=1+color[lp[i]];//But shouldnt this be 1+color[i/lp[i]]?
- maxI=max(color[i],maxI);
- }
- }
- cout<<maxI<<endl;
- for(ll int i=2;i<=n+1;i++) cout<<color[i]<<" ";
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement