fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. const int N = 5e5;
  7.  
  8. int n, spf[N+1], f[N+1];
  9.  
  10. void precompute() {
  11. for (int i = 2; i <= N; i++)
  12. if (spf[i] == 0)
  13. for (int j = i; j <= N; j += i)
  14. if (spf[j] == 0) spf[j] = i;
  15. f[1] = 1;
  16. for (int i = 2; i <= N; i++)
  17. f[i] = f[i / spf[i]] + 1;
  18. }
  19.  
  20. void solve() {
  21. cin >> n;
  22. int k = 0;
  23. for (int i = 1; i <= n; i++)
  24. k = max(k, f[i]);
  25. cout << k << '\n';
  26. for (int i = 1; i <= n; i++)
  27. cout << f[i] << ' ';
  28. cout << '\n';
  29. }
  30.  
  31. int main() {
  32. ios_base::sync_with_stdio(false); cin.tie(NULL);
  33.  
  34. precompute();
  35.  
  36. int tests = 1; cin >> tests;
  37. while (tests--) solve();
  38.  
  39. #ifndef ONLINE_JUDGE
  40. cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  41. #endif
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 7516KB
stdin
2
3
4
stdout
2
1 2 2 
3
1 2 2 3