B. Sherlock and his girlfriend

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<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b) for(int i=a;i<=b;i++)
#define rrep(a,b) for(int j=a;j<=b;j++)
#define per(a,b) for(int i=a;i>=b;i--)
#define pper(a,b) for(int j=a;j>=b;j--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
const int N = 2e5 + 100;
const int  INF = 0x3f3f3f3f;
ll gcdd(ll a, ll b)
{
    if (b) while ((a %= b) && (b %= a));
    return a + b;
}
ll h[N], ne[N], w[N], to[N], idx;
void add(int a, int b, int c)
{
    to[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
const int mod = 998244353;
ll t, n, m, a, b, c, x, k, cnt, ans, ant, sum, p;
ll arr[N], brr[N], crr[N];
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;
        }
    }
}
int main()
{
    ol();
    cin >> n;
    if (n <= 2)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 2 << endl;
    }
    
    for (int i = 2;i <= n + 1;i++)
    {
        if (!book[i])
        {
            cout << 1 << ' ';
        }
        else
        {
            cout << 2 << ' ';
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值