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
3
output
2
1 1 2
input
4
output
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.

题意:将数字染色,如果有一个相同的素数除数,则颜色不同,使得颜色种类最少

解法:

1 素数颜色1,其他颜色2

2 看样列怎么想也就两种(不过n<=2就是一种)

 #include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
map<int,int>Mp;
int main(){
int n;
cin>>n;
if(n<=){
cout<<""<<endl;
for(int i=;i<=n;i++){
cout<<"1 ";
}
return ;
}
n=n+;
for(int i=;i<=n;i++){
for(int j=i+i;j<=n;j+=i){
Mp[j]=;
}
}
cout<<""<<endl;
for(int i=;i<=n;i++){
if(Mp[i]){
cout<<Mp[i]<<" ";
}else{
cout<<"1 ";
}
}
return ;
}

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) B的更多相关文章

  1. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀

    A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A

    Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each ...

  3. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT

    题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...

  4. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

    前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...

  5. 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem

    再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...

  6. 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...

  7. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D

    Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlo ...

  8. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C

    Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an aff ...

  9. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    感觉自己做有关区间的题目方面的思维异常的差...有时简单题都搞半天还完全没思路,,然后别人提示下立马就明白了...=_= 题意:给一个含有n个元素的数组和k,问存在多少个区间的和值为k的次方数. 题解 ...

随机推荐

  1. Python序列——Unicode

    Unicode是什么 Python中的Unicode 编码与解码 在应用中使用Unicode的建议 1. Unicode是什么 Unicode是对字符进行编码的一种标准.而utf8或者utf-8是根据 ...

  2. bzoj2132【圈地计划】

    题面 思路: 一开始以为和为了博多一样,两边连一样的,后来发现中间连负边的话根本不会割,即割断两块收益为负,所以WA的起飞…… 正解是先黑白染色,每个点和它周围的点连边方式不同.对于黑点A,S--&g ...

  3. 【错误信息】springMVC No mapping found for HTTP request with URI

    出现这个问题的原因是在web.xml中配置错了:

  4. pycharm 开发连接linux 服务器

    这样就可以了.....

  5. bzoj 2006 [NOI2010]超级钢琴——ST表+堆

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2006 每个右端点的左端点在一个区间内:用堆记录端点位置.可选区间,按价值排序:拿出一个后也许 ...

  6. kafka之五:如何手动更新Kafka中某个Topic的偏移量

    本文介绍如何手动跟新zookeeper中的偏移量.我们在使用kafka的过程中,有时候需要通过修改偏移量来进行重新消费.我们都知道offsets是记录在zookeeper中的,所以我们想修改offse ...

  7. Strom配置说明

    在进群生产环境下运行Topology和在本地模式下运行非常相似.下面是步骤: 1.定义Topology(如果使用Java开发语言,则使用TopologyBuilder来创建) 2.使用StormSub ...

  8. 微软silverlight Analytics FrameWork

    本文转自:http://kevinfan.blog.51cto.com/1037293/334622/ http://kevinfan.blog.51cto.com/1037293/334622   ...

  9. [转]windows10 1703 鼠标右键打开命令提示符cmd

    https://answers.microsoft.com/zh-hans/windows/forum/windows_10-performance/windows10-1703/8bdfdfea-4 ...

  10. CF-807C

    C. Success Rate time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...