Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 ≤ n ≤ 100000) — the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
input
Copy
3
output
Copy
2 1 1 2
input
Copy
4
output
Copy
2 2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
夏洛克有了一个新女友(真不像他!)。情人节快到了,他想送她一些珠宝。
他买了n件珠宝。第i件的价格等于i+1,也就是说,这些珠宝的价格是2,3,4,...n+1。
华生给夏洛克出了个难题:给这些珠宝上色,如果其中一件的价格是另一件价格的质除数,那么两件珠宝的颜色就不会相同。此外,华生还要求他尽量减少使用不同颜色的数量。
请帮助夏洛克完成这个微不足道的任务。
输入
唯一的一行包含单个整数n(1≤n≤100000)--珠宝的数量。
输出
第一行输出应包含一个整数k,即在给定的约束条件下,可以用来给珠宝片着色的最小颜色数。
下一行应该包含n个空格分隔的整数(在1和k之间),这些整数按照价格递增的顺序指定每件珠宝的颜色。
如果有多种方法可以用k种颜色给珠宝上色,你可以输出其中任何一种。
例子
inputCopy
3
outputCopy
2
1 1 2
输入复制
4
输出拷贝
2
2 1 1 2
备注
在第一个输入中,价格为2、3、4的第一件、第二件和第三件珠宝的颜色分别为1、1和2。
在这种情况下,由于2是4的质除数,价格为2和4的珠宝的颜色必须是不同的。
解析,比赛的时候连题目都没看明白,就在那里框框写然后框框wa
是真的没看明白质因数是啥意思然后看样例有个2和4然后就彻底理解错了
比赛完翻了好题解才算是明白,这个题目就是单纯的判断质数 的题目,是真的没看懂,吸取教训了
欧拉筛,欧拉筛,筛出质数。在强记板子
bool book[N] = { 1,1 };
void ol()
{
for (int i = 2;i <= 100010;i++)
{
if (!book[i])arr[++k] = i;
for (int j = 1;j <= k;j++)
{
if (i * arr[j] > 100010)break;
book[i * arr[j]] = 1;
if (i % arr[j] == 0)break;
}
}
}
ac代码
#include
#include
#include
#include
#include
#include
#include
#include
#include