当前位置: 首页 > news >正文

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 << ' ';}}
}

http://www.lryc.cn/news/28637.html

相关文章:

  • Spring SpEL表达式
  • Nginx反向代理原理详解与配置
  • Happen-Before从入门到踹门
  • 电力系统系统潮流分析【IEEE 57 节点】(Matlab代码实现)
  • Java——N皇后问题
  • Mybatis一级缓存与二级缓存
  • LQB,手打,PCF8591,ADDA转换,AD1是光敏电阻,AD3是电位器,DA输出
  • 【计组笔记06】计算机组成与原理之控制器和总线结构
  • elisp简单实例: auto-save
  • 写字楼/园区/购物中心空置率太高?快用快鲸智慧楼宇系统
  • 【JavaSE】数组的定义和使用(上)
  • 计算机的学习路线
  • TD算法超详细解释,一篇文章看透彻!
  • 4.1 路由器(华硕 官改/梅林 华为 小米 路由) 使用花生壳 实现远程管理
  • 内容算法解读:提高内容摘要与原文的一致性(Faithfulness)
  • python用openpyxl包操作xlsx文件,统计表中合作电影数目最多的两个演员
  • Lesson12---人工神经网络(1)
  • 算法练习-排序(二)
  • 202302读书笔记|《长安的荔枝》——只要肯努力,办法总比困难多
  • java封装继承多态详解
  • 【uni-app教程】UniAPP 常用组件和 常用 API 简介# 知心姐姐聊天案例
  • 阿尔法开发板 .bin 文件烧写
  • Ceres-Solver 安装与卸载ubuntu20.04
  • 汇编系列02-借助操作系统输出Hello World
  • 【2023unity游戏制作-mango的冒险】-前六章API,细节,BUG总结小结
  • 进程控制及其操作
  • Git常用命令复习笔记
  • 代码随想录算法训练营day49 | 动态规划 123.买卖股票的最佳时机III 188.买卖股票的最佳时机IV
  • 【教学典型案例】14.课程推送页面整理-增加定时功能
  • 【算法基础】DFS BFS 进阶训练