fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, a[1000005];
  6.  
  7. void sangnt(){
  8. for (int i = 2; i <= 9999; i++){
  9. if (a[i]==0){
  10. for (int j = i*i; j <= 100001; j+=i){
  11. a[j] = 1;
  12. }
  13. }
  14. }
  15. }
  16.  
  17. int main(){
  18. cin >> n;
  19. sangnt();
  20. if (n==1) cout << "1\n1";
  21. else if (n==2) cout << "1\n1 1";
  22. else{
  23. cout << 2 << endl;
  24. for (int i = 2; i <= n+1; i++){
  25. if (!a[i]) cout << "1 ";
  26. else cout << "2 ";
  27. }
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 19968KB
stdin
100
stdout
2
1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1