Codeforces 1174C Ehab and a Special Coloring Problem
题目链接:http://codeforces.com/problemset/problem/1174/C

题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数组中最大值最小化。
思路:打个素数表,每个质数肯定互质所以我们令第一个质数为1,第二个质数为2...依次类推,然后根据 算术基本定理 ,合数就让它等于第一个分解的质数啦。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN= 2e5 +;
int vis[MAXN];
int a[MAXN];
int n;
void init()
{
vis[] = ;
vis[] = ;
for(int i = ;i < MAXN;i ++)
{
if(! vis[i])
{
vis[i] = ;
for(int j = *i;j <= MAXN; j += i)
{
vis[j] = ;
}
}
}
}
int gcd(int a,int b)
{
if(b == )
return a;
else return gcd(b,a%b);
}
int main()
{
int n;
scanf("%d",&n);
memset(vis,,sizeof(vis));
init();
int cnt = ;
for(int i = ;i <= n;i++)
{
if(!vis[i]) a[i] = cnt++;
else
{
for(int j = ;j <= i;j++)
{
if(gcd(i,j) != )
{
a[i] = a[j];
break;
}
}
}
}
for(int i = ;i <= n;i++)
{
printf("%d ",a[i]);
}
return ;
}
Codeforces 1174C Ehab and a Special Coloring Problem的更多相关文章
- 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 i ...
- CF1174C Ehab and a Special Coloring Problem(数论)
做法 与\(x\)互质的数填不同的数,把有向关系表示出来,发现边数是不能承受的 反过来想,成倍数关系填相同的数,把这些数想象成一条链,而这条链开始的数一定是质数,\(\sum\limits_{prim ...
- Ehab and a Special Coloring Problem
You're given an integer nn. For every integer ii from 22 to nn, assign a positive integer aiai such ...
- Codeforces 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- Codeforces.1088D.Ehab and another another xor problem(交互 思路)
题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...
- 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 ...
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
随机推荐
- luoguP2148 [SDOI2009]E&D [sg函数][组合游戏]
题目描述 小E 与小W 进行一项名为“E&D”游戏. 游戏的规则如下: 桌子上有2n 堆石子,编号为1..2n.其中,为了方便起见,我们将第2k-1 堆与第2k 堆 (1 ≤ k ≤ n)视为 ...
- MyEclipse6.0中使用aptana插件,添加jquery提示功能
MyEclipse6.0中使用aptana插件,添加jquery提示功能 第一:查看当前MyEclipse集成的eclipse的版本,, 查看路径 D:/MyEclipse 6.0/eclips ...
- NOIp2018集训test-10-20 (bike day6)
B 君的第一题 lanzhou $x^{\frac{p-1}{2}}\equiv 1(mod\ p)$ $x\equiv x*x^{\frac{p-1}{2}} (mod\ p)$ $x\equiv ...
- (转)OpenFire源码学习之七:组(用户群)与花名册(用户好友)
转:http://blog.csdn.net/huwenfeng_2011/article/details/43413651 Group 在openfire中的gorop——组,也可以理解为共享组.什 ...
- 剑指offer——71扑克牌中的顺子
题目描述 LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决 ...
- testNG官方文档翻译-4 运行TestNG
TestNG可以通过不同的方法触发运行: 命令行 ant Eclipse IntelliJ's IDEA
- http over git server
编译安装git 参考 <CentOS7编译安装git> 安装httpd yum install httpd -y 安装gitweb yum install gitweb -y 创建项目根目 ...
- python去除rpm仓库中同名低版本的包
编程思路1 遍历目标路径的rpm包并保存特性包列表: 2 利用python模块rpmUtils提取RPM包的特征信息:包名 版本号 架构 3 遍历特性列表中存在重复包名的rpm, 将低版本的rpm包 ...
- 高效IO之File文件操作类的基础用法(二)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 前言 众所周知Java提供File类,让我们对文件进行操作,下面就来简单整理了一 ...
- JVM调优参数设置?
-Xms20M 表示设置堆容量的最小值为20M,必须以M为单位 -Xmx20M 表示设置堆容量的最大值为20M,必须以M为单位.将-Xmx和-Xms设置为一样可以避免堆自动扩展.大的项目-Xmx和-X ...