You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
// 欧拉筛
|
|
|
|
|
const int N = 1e5 + 10;
|
|
|
|
|
int primes[N], cnt; // primes[]存储所有素数
|
|
|
|
|
bool st[N]; // st[x]存储x是否被筛掉
|
|
|
|
|
void get_primes(int n) {
|
|
|
|
|
for (int i = 2; i <= n; i++) {
|
|
|
|
|
if (!st[i]) primes[cnt++] = i;
|
|
|
|
|
for (int j = 0; primes[j] * i <= n; j++) {
|
|
|
|
|
st[primes[j] * i] = true;
|
|
|
|
|
if (i % primes[j] == 0) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
// 加快读入
|
|
|
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
|
|
|
// 筛出区间内所有质数
|
|
|
|
|
get_primes(N - 1);
|
|
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
// 1、质数与质数之间没有边
|
|
|
|
|
// 2、合数可以由它的质因子连边,那么合数与合数之间就是没有边
|
|
|
|
|
// 根据上面的性质,这就是一个由质数集合与合数集合构成的一个二分图,根据二分图染色办法知道,只需要1~2种颜色即可
|
|
|
|
|
n <= 2 ? puts("1") : puts("2"); // n=3时,价值就会出现4,就是有合数出现,这时就是二分图,而且中间有边连接了
|
|
|
|
|
|
|
|
|
|
for (int i = 2; i <= n + 1; i++)
|
|
|
|
|
!st[i] ? printf("1 ") : printf("2 "); // 没有被筛掉的话,是质数,输出1,否则合数输出2
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|