输入样例1:
3
输出样例1:
- 2
- 1 1 2
输入样例2:
4
输出样例2:
- 2
- 2 1 1 2
- #include
- #define endl '\n'
- #define int long long
- using namespace std;
- const int N = 1e5 + 10;
- bool iscomp[100000005]; //是不是合数
- int arr[N];
- int num;
- void isCop(bool iscomp[], int n)
- {
- iscomp[1] = 1; //1的特判
- for (int i = 2;i <= n / i;i++)
- {
- if (iscomp[i] == 0) //如果是素数
- for (int j = i * i;j <= n;j += i) //将他的倍数记为合数
- iscomp[j] = 1; //标记
- }
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- //数据预处理
- int n = 1e5+10;//n代表的是判断的数据范围;
- isCop(iscomp, n);
- int num;
- cin >> num;
- if (num > 2) {
- cout << '2' << endl;
- }
- else cout << '1' << endl;
- for (int i = 1;i <= num;i++) {
- if (iscomp[i+1])cout << '2' << ' ';
- else cout << '1' << ' ';
- }
- return 0;
- }