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的次方数. 题解 ...
随机推荐
- mtk6589显示子系统笔记(一)
拿到MT6589的版本不久,发现显示系统代码结构改变很大.做些备忘,后续不忙的时候可以继续看. MT6589之前的MTK的Android系统显示系统同featurePhone基本一致. 先来回顾下MT ...
- Ubuntu环境下配置Android Studio【转】
本文转载自:https://www.jianshu.com/p/1f6295f9c955 之前学习Android开发的时候,一直跟各种教程一样,使用的是Eclipse+ADT,主要是比较方便,容易上手 ...
- RBAC打造通用web管理权限
https://www.cnblogs.com/lamp01/p/6576432.html https://www.imooc.com/learn/799
- CSS元素水平垂直居中方法总结(主要对大漠以及张鑫旭博客所述方法进行了归纳)
本文主要是对主流居中方法进行了归纳,有些地方甚至就是把别人的代码直接复制过来的,没有什么自己的东西,除了大漠以及张鑫旭的方法外,还有来自司徒正美.怿飞博客的几个方法 以下方法,由于测试环境的原因,IE ...
- linux应用之samba服务的安装及配置(centos)
一.安装方式: 本文通过yum来重新进行Samba服务器的安装与配置. 二.Samba的简介: Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Me ...
- Yii的缓存机制之页面缓存
页面缓存是不能通过片段缓存来实现的,因为布局和内容不能同时缓存.只能通过过滤器来生成缓存. 实现方法: 在控制器里使用过滤器来实现 function filters (){ return array( ...
- 测试jdbc连接下,mysql和mycat的吞吐性能
最近一个项目需要数据库有较大的吞吐量,因为项目要求的访问量和数据量较大,决定采用一个数据库中间件来对数据库进行管理.经过一番查询,决定使用阿里的一个开源项目-mycat.因为mycat基于mysql, ...
- codevs 1147 排座椅
传送门 题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情.不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接 ...
- codevs 4768跳石头
传送门 4768 跳石头 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一年一度的“跳石头”比赛又要开始了! 这项比赛将在 ...
- 如何理解Web应用程序的MVC模型?
View,也就是视图/视野,是你真正看到的,而非想象中的 Model.Controller,也就是控制器,是你用来改变 Model 方式.简单的说 Controller 和 View 分别是 Mode ...