ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) B
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.
The only line contains single integer n (1 ≤ n ≤ 100000) — the number of jewelry pieces.
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.
3
2
1 1 2
4
2
2 1 1 2
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...
- 【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不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...
- 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...
- 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 ...
- 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 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
感觉自己做有关区间的题目方面的思维异常的差...有时简单题都搞半天还完全没思路,,然后别人提示下立马就明白了...=_= 题意:给一个含有n个元素的数组和k,问存在多少个区间的和值为k的次方数. 题解 ...
随机推荐
- linux命令行快捷键记录
摘自: http://www.cnblogs.com/webzhangnan/p/3221410.html [移动光标] Ctrl+A 标移到行首.它在多数文本编辑器和 Mozilla 的 URL 字 ...
- Swift下表和方法
本文将同时阐述Swift的方法和下标,因为根据我的理解,从某种程度上讲,下标的本质也是方法. 方法 众所周知,在支持面向对象的语言里,方法一般分为两种:实例方法和类方法(在有的语言中,「类方法」被称为 ...
- 「NOIP2002」「Codevs1099」 字串变换(BFS
1099 字串变换 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知有两个字串 $A$, ...
- VirtualBox下安装ubuntu图文教程以及软件安装
一. 下载安装VirtualBox 官网下载VirtualBox,目前版本:VirtualBox 5.1.8 for Windows hosts x86/amd64 下载好了安装VirtualBox, ...
- JAVA 中的堆和栈
栈与堆都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆. Java的堆是一个运行时数据区,类的对象从中分配空间.这些对象通过new.n ...
- 关于git被误删除的分支还原问题
在开发过程中, 有可能会将正在开发的本地分支误删, 本地分支被删除时, 如果已经将本地分支的变更推送到了远端, 还没有问题, 如果被删除的本地分支只提交了没有推送到远端, 就悲剧了, 相当于在你上一次 ...
- Prime Independence
题意: 对于给定集合,求解最大的子集合,使得集合内两两之商不为质数. 解法: 考虑对于每一个数字分解质因数可以得到 $O(nloglogNUM)$ 条两个数字不可以出现在同一集合的信息. 同时发现一条 ...
- 总结open与fopen的区别
https://www.zybuluo.com/yiltoncent/note/87461 参考链接1 参考链接2 对于这两个名字很类似的函数,对于很多初学者来说,不容易搞清楚它们有什么不同,只知道按 ...
- sql之视图、触发器、函数、存储过程、事务
视图 # 视图也是一张表,但在data文件里只有表结构,没有表数据 # 不建议使用,扩展性差,程序需改变时,依赖的视图也要改变 # 视图牵涉到多张表时,视图中的记录不能修改. create view ...
- sql语句之连表操作
内连接 select * from employee inner join department on employee.dep_id = department.id 左连接 在内连接的基础上保留左表 ...