链接: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的更多相关文章

  1. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  2. 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 题意: 给出一个 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale

    后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...

  7. 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/ ...

  8. Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学

    题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可 ...

  9. 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^ ...

随机推荐

  1. ELK之方便的日志收集、搜索、展示工具

    大家在做分部署系统开发的时候是不是经常因为查找日志而头疼,因为各服务器各应用都有自己日志,但比较分散,查找起来也比较麻烦,今天就给大家推荐一整套方便的工具ELK,ELK是Elastic公司开发的一整套 ...

  2. CATTI二级口译训练

    Vice chancellor, faculty members and dear students, It is my great pleasure and privilege to visit C ...

  3. laravel基础课程---5、路由复习(路由作用)

    laravel基础课程---5.路由复习(路由作用) 一.总结 一句话总结: 有利于百度收录,及SEO优化 1.路由书写 (D:\laravel\yzmedu\yzm2\routes\web.php) ...

  4. html5--1.10绝对路径和相对路径

    html5--1.10绝对路径和相对路径 学习要点: 绝对路径和相对路径 1.绝对路径 需要指出链接资源的绝对位置,与你的HTML文档的位置无关: 1. 服务器中的位置:href="http ...

  5. __declspec(dllimport)的小秘密(转)

    昨天和同事使用一个dll(lib+dll)的时候,发现他在引用头文件是,并没有使用__declspec(dllimport),但是程序完全运行正常,不明觉厉下,去网上翻了下资料,原来是链接器的原因,这 ...

  6. Python 静态方法和类方法的区别

    python staticmethod and classmethod Though classmethod and staticmethod are quite similar, there’s a ...

  7. [转]sql where 1=1和 0=1 的作用

    sql where 1=1和 0=1 的作用 原文地址:http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html where 1=1; ...

  8. selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。

    转自:https://blog.csdn.net/xxj19950917/article/details/73002046

  9. Unity3d笔记

    当变量重命名后,已序列化保存的值会丢失,如果希望继续保留其数值,可使用FormerlySerializedAs,如下代码所示: [UnityEngine.Serialization.FormerlyS ...

  10. Http协议-概要

    Http协议(超文本传输协议)是位于TCP/IP结构中的应用层的一种传输协议,规定了万维网服务器之间相互通信的规则.比如比较常见的Web浏览器客户端与应用服务器的通信!万维网服务器之间互相通信的时候往 ...