Advertisement
Singasking

Untitled

Jan 21st, 2023 (edited)
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. using namespace std;
  2. #define ll long long
  3. #include <bits/stdc++.h>
  4. int main() {
  5.  ll   int n;
  6.     cin>>n;
  7.     vector<ll int> lp(n+2,1);
  8.     for(ll int i=0;i<=n+1;i++) lp[i]=i;
  9.     vector< ll int> color(n+2,1);
  10.     for(ll int i=2;i<=n+1;i++) {
  11.         if(lp[i]==i) {
  12.             for(ll int j=i*i;j<=n+1;j+=i) {
  13.                if(lp[j]==j) lp[j]=i;
  14.             }
  15.         }
  16.            
  17.     }
  18.    ll int maxI=1;
  19.     for(ll int i=2;i<=n+1;i++) {
  20.      if(lp[i]!=i) {
  21.          color[i]=1+color[lp[i]];//But shouldnt this be 1+color[i/lp[i]]?
  22.          maxI=max(color[i],maxI);
  23.      }  
  24.     }
  25.     cout<<maxI<<endl;
  26.     for(ll int i=2;i<=n+1;i++) cout<<color[i]<<" ";
  27.     cout<<endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement