Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem
链接:https://codeforces.com/contest/1174/problem/C
题意:
You're given an integer nn. For every integer ii from 22 to nn, assign a positive integer aiai such that the following conditions hold:
- For any pair of integers (i,j)(i,j), if ii and jj are coprime, ai≠ajai≠aj.
- The maximal value of all aiai should be minimized (that is, as small as possible).
A pair of integers is called coprime if their greatest common divisor is 11.
思路:
筛法,把下标为素数的赋予新值,他的倍数再赋予同样的值即可。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t; int a[MAXN]; int main()
{
cin >> n;
int cnt = 0, pos = 0;
for (int i = 2;i <= n;i++)
{
if (a[i] != 0)
continue;
// cout << i << endl;
a[i] = ++pos;
cnt++;
int j = 2*i;
while (j <= n)
{
a[j] = pos;
j += i;
cnt++;
}
// if (cnt >= n-1)
// break;
}
for (int i = 2;i <= n;i++)
cout << a[i] << ' ' ;
cout << endl; return 0;
}
Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem的更多相关文章
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...
- Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...
- Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...
- Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数 联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)
题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...
随机推荐
- html5 canvas画饼
1. [图片] lxdpie.jpg 2. [文件] lqdpie.html ~ 801B 下载(7) <!DOCTYPE HTML PUBLIC "-//W3C//DTD ...
- 草原psd素材
草原PSD素材,草原,风景,蓝天白云,飞鸟,阳光,绿色,草地. http://www.huiyi8.com/caoyuan/psd/
- 【Codeforces】894E.Ralph and Mushrooms Tarjan缩点+DP
题意 给定$n$个点$m$条边有向图及边权$w$,第$i$次经过一条边边权为$w-1-2.-..-i$,$w\ge 0$给定起点$s$问从起点出发最多能够得到权和,某条边可重复经过 有向图能够重复经过 ...
- 国内镜像pip
建议非清华大学校内的使用这个镜像: http://e.pypi.python.org/simple(这也是一个http://pypi.v2ex.com/simple),清华校内的就使用这个:http: ...
- 51nod_1236_序列求和 V3 _组合数学
51nod_1236_序列求和 V3 _组合数学 Fib(n)表示斐波那契数列的第n项,Fib(n) = Fib(n-1) + Fib(n-2).Fib(0) = 0, Fib(1) = 1. (1, ...
- drop asm disk、撤销drop asm disk
drop asm disk.撤销drop asm disk drop asm disk:SQL> alter diskgroup XXX offline disk XXXX drop after ...
- Python3解leetcode Same TreeBinary Tree Level Order Traversal II
问题描述: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, fro ...
- sql基础内容2
-- day16课程内容 --CREATE DATABASE day16;USE day16; -- *************一.数据约束********************------ 1.1 ...
- 信息安全:Token
ylbtech-信息安全:Token Token(计算机术语) 在计算机身份认证中是令牌(临时)的意思,在词法分析中是标记的意思. 1.令牌返回顶部 1.令牌 (信息安全术语) Token, 令牌,代 ...
- python3 + selenium + eclipse 中报错:'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
解决:提示chrome driver没有放置在正确的路径下,于是下载chrome dirver,然后放置到C:\Python36的目录下,再次运行就OK了!