CF776B Sherlock and his girlfriend
题目地址
题解
这题很有意思啊qwq。本来是写算出每个数的质约数的,然后写到一半发现,质约数互相不影响,有质约数的数肯定是合数。
所以合数染一种色,质数染一种色就好
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
#define N 100010
#define ll long long
#define inf 2147483647
int p[N], n, a[N], vis[N];
int ans[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d", &n);
int cnt = 0; ++n;
for(int i = 2; i <= n; ++i) {
if(!vis[i]) p[++cnt] = i;
for(int j = 1; j <= cnt && i * p[j] <= n; ++j) {
vis[i * p[j]] = 1;
if(i % p[j] == 0) break;
}
}
int mx = 1;
for(int i = 2; i <= n; ++i) {
if(!vis[i]) ans[i - 1] = 1;
else ans[i - 1] = 2, mx = 2;
}
printf("%d\n", mx);
for(int i = 1; i < n; ++i) printf("%d ", ans[i]);
return 0;
}
CF776B Sherlock and his girlfriend的更多相关文章
- 「CF779B」「LOJ#10201.」「一本通 6.2 练习 4」Sherlock and His Girlfriend(埃氏筛
题目描述 原题来自:Codeforces Round #400 B. Sherlock 有了一个新女友(这太不像他了!).情人节到了,他想送给女友一些珠宝当做礼物. 他买了 nnn 件珠宝.第 iii ...
- Sherlock and His Girlfriend(信息学奥赛一本通 1623)
[题目描述] 原题来自:Codeforces Round #400 B. Sherlock 有了一个新女友(这太不像他了!).情人节到了,他想送给女友一些珠宝当做礼物. 他买了 n 件珠宝.第 i 件 ...
- Sherlock and His Girlfriend题解
题目描述 Sherlock 有了一个新女友(这太不像他了!).情人节到了,他想送给女友一些珠宝当做礼物. 他买了 n件珠宝.第i 件的价值是i+1.那就是说,珠宝的价值分别为2,3,4,-,n+1 . ...
- Codeforces_776B: Sherlock and his girlfriend(素数筛)
题目链接 题意:对2~n+1染色,一个数不能与其素因子同色. 故而只需两种颜色即可,素数染1,合数染2便可满足条件 #include<bits/stdc++.h> using namesp ...
- 【Codeforces 776B】Sherlock and his girlfriend
[题目链接] 点击打开链接 [算法] 将所有质数染成1,合数染成2即可 [代码] #include<bits/stdc++.h> using namespace std; #define ...
- 一本通1623Sherlock and His Girlfriend
1623:Sherlock and His Girlfriend 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自:Codeforces Round ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...
- loj题目总览
--DavidJing提供技术支持 现将今年7月份之前必须刷完的题目列举 完成度[23/34] [178/250] 第 1 章 贪心算法 √ [11/11] #10000 「一本通 1.1 例 1」活 ...
- oi初级数学知识
一.先是一些整除的性质: •整除:若a=bk,其中a,b,k都是整数,则b整除a,记做b|a. •也称b是a的约数(因数),a是b的倍数 •显而易见的性质: •1整除任何数,任何数都整除0 •若a|b ...
随机推荐
- wxpython(python3.5)安装
安装步骤: http://blog.csdn.net/xiaodong193/article/details/51920283 注意:安装软件前需要阅读其中的README.txt,可快速知道安装方法, ...
- Linux基础命令---arping
arping arping指令用于发送arp请求到一个相邻的主机,在指定网卡上发送arp请求指定地址,源地址使用-s指定.该指令可以直径ping MAC地址,找出哪些地址被哪些电脑使用了. 此命令的适 ...
- 1113: No mapping for the Unicode character exists in the target multi-byte code page
windows版本nginx启动 报错. 启动方式:到nginx所在目录执行:nginx.exe -c conf\nginx.conf 原因:所在路径中含有中文字符. 解决:换个没有中文的路径.
- AtCoder Beginner Contest 087 (ABC)
A - Buying Sweets 题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a Time limit : 2sec / Memory l ...
- Codeforces 124A - The number of positions
题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't ...
- bzoj1625 [Usaco2007 Dec]宝石手镯
01背包 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring& ...
- linux OS与SQL修改时区,系统时间
linux修改系统时间和linux查看时区.修改时区的方法 一.查看和修改Linux的时区 1. 查看当前时区命令 : "date -R" 2. 修改设置Linux服务器时区方法 ...
- Python+OpenCV图像处理(三)—— Numpy数组操作图片
一.改变图片每个像素点每个通道的灰度值 (一) 代码如下: #遍历访问图片每个像素点,并修改相应的RGB import cv2 as cv def access_pixels(image): prin ...
- MyEclipse如何清除废弃的工作空间
1.MyEclipse如何清除废弃的工作空间Windows--->Preferences--->General--->Startup and Shutdown--->Works ...
- RTSP 与 RTMP 协议 (转)
源: RTMP协议与RTSP协议比较 RTSP 与 RTMP 协议 RTSP Spec中文版(1-11) RTSP协议 流媒体之rtsp篇 H264视频传输.编解码----RTSP协议