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 ...
随机推荐
- python3(socket 实现udp,tcp套接字编程)
#coding=utf-8 #客户端程序TCP 连接 import socket s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connec ...
- MySql 学习参考目录
[1]< MySql 数据类型> [2]< MySql 基础 > [3]< MySql 存储过程 > PS:个人认为,如上总结超值. Good Good Study ...
- Python数据类型深入学习之数字
一. 数字常量 1. 下面来看看Python的数字常量中都要哪些类型: 数字 常量 129,-89,0 一般整数 9999848499999L,4594646469l 长整型数(无限大小) 1.232 ...
- android安全检测工具,梆梆安全 - 防止反编译|APP安全加固|应用加固|盗版监测
android安全检测工具,梆梆安全 - 防止反编译|APP安全加固|应用加固|盗版监测https://dev.bangcle.com/ 业内专业的应用加固服务供应商 帮助数十万APP抵御破解风险,早 ...
- e3.7.2-MyEclipse-10.7安装SVN插件
MyEclipse 10.7的版本是:e3.7.2,要求是匹配该插件eclipse_svn_site-1.10.1的版本,否则无效 将eclipse_svn_site-1.10.1插件文件夹直接拷贝到 ...
- ES6知识整理(6)--Symbol函数
(文章会同步到博客园,技术类文章还是该让搜索引擎察觉比较好) symbol是js的第7种数据类型: 7种分别是:undefined.null.boolean(布尔).string(字符串).numbe ...
- How to click on a point on an HTML5 canvas in Python selenium webdriver
https://stackoverflow.com/questions/29624949/how-to-click-on-a-point-on-an-html5-canvas-in-python-se ...
- 使用mac自带终端修改hosts
修改mac host文件绑定域名 打开终端 在终端terminal中输入sudo vi/etc/hosts sudo与vi之间有一个空格 上一步输入完成之后按enter回车键,如果当前用户账号有密码, ...
- Python 操作 mysql数据库的一个小小的基础案例,小白新手,以备后用~~
model.py 中的代码 # Create your models here. # 书和作者一对多 class Author(models.Model): name = models.CharFie ...
- What is probabilistic programming? | 中文翻译
What is probabilistic programming? | 中文翻译 Probabilistic languages can free developers from the compl ...