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^ ...
随机推荐
- 纯CSS3实现淡入淡出下拉菜单
纯CSS3实现淡入淡出下拉菜单是一款比较简单清新的CSS3教程下拉菜单,这款下拉菜单是垂直方向的,点击主菜单项可以展开和折叠子菜单,在展开折叠的过程中伴随着淡入淡出的动画效果 源代码:http://w ...
- html5基本格式
html5基本格式 学习要点: HTML5 文档的基本格式 2. 开发工具的基本操作 一. 文档基本格式 <!DOCTYPE html> 文档声明,告诉计算机这是一个HTML5文档. ...
- POSTGRESQL 导入导出
安装postgresql yum install postgresql postgresql-server mysql占用端口3306 pgsql是5432 2 导入整个数据库 psql -U pos ...
- python-多线程2-线程同步
线程同步: 一个场景: 一个列表里所有元素都是0,线程A从后向前把所有元素改成1,而线程B负责从前往后读取列表并打印. 那么,可能线程A开始改的时候,线程B便来打印列表了,输出就变成一半0一半1,这就 ...
- 【译】在ES6中如何优雅的使用Arguments和Parameters
原文地址:how-to-use-arguments-and-parameters-in-ecmascript-6 ES6是最新版本的ECMAScript标准,而且显著的改善了JS里的参数处理.我们现在 ...
- android自定义控件(六) 刷新
三种得到LinearInflater的方法 a. LayoutInflater inflater = getLayoutInflater(); b. LayoutInflater localinfla ...
- BZOJ_3744_Gty的妹子序列
BZOJ3744: Gty的妹子序列 https://lydsy.com/JudgeOnline/problem.php?id=3744 分析: 预处理出来每一块块首到所有位置的逆序对数. 查询时主席 ...
- Out of resources when opening file ‘./xxx.MYD’ (Errcode: 24)解决方法
今天朋友向我反映网站出现错误:Out of resources when opening file './xxx.MYD' (Errcode: 24)错误是因为打开的文件数超过了my.cnf的--op ...
- Poj_1088_滑雪(DP)
一.Description(poj1088) Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载 ...
- Zigbee协议栈--Z-Stack的使用
使用方法简介:一般情况下用户只需要额外添加三个文件就可以完成一个项目.一个是主文件,存放具体的任务事件处理函数:一个是这个主文件的头文件:另外一个是以Osal开头的操作系统接口文件,是专门存放任务处理 ...