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

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

  2. CF1174C Ehab and a Special Coloring Problem(数论)

    做法 与\(x\)互质的数填不同的数,把有向关系表示出来,发现边数是不能承受的 反过来想,成倍数关系填相同的数,把这些数想象成一条链,而这条链开始的数一定是质数,\(\sum\limits_{prim ...

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

  4. Codeforces 1088E Ehab and a component choosing problem

    Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...

  5. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

  6. Codeforces.1088D.Ehab and another another xor problem(交互 思路)

    题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...

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

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

  9. [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& ...

随机推荐

  1. Hbase节点的管理|服役和退役节点

    Base节点的管理 1.服役(commissioning) 当启动regionserver时,regionserver会向Hmaster注册并开始接收本地数据,开始的时候,新加入的节点不会有任何数据, ...

  2. 创建一个apk:按钮-click-文字display,测试apk;安装在真机进行调试的方法

    问题引入: 怎么样在一个app做event事件?例如touch操作,滑动操作,和按键事件(back,home等) 回答1:device.touch(x,y) ---获取device对象,然后touch ...

  3. MFC的回调函数

      MFC中应该有两类回调函数:一类是源自C的传统回调函数,此类回调函数若非定义为全局函数,而定义在类中的话,要添加static约束,常见的有EnumXXX():一类是消息响应函数,通过成员函数指针实 ...

  4. 4种XML解析器

    <?xml version="1.0" encoding="UTF-8"?> <Result> <VALUE> <NO ...

  5. C++——extern

    1.当它与"C"一起连用时,如: extern "C" void fun(int a, int b);则告诉编译器在编译fun这个函数名时按着C的规则去翻译相应 ...

  6. POJ 1329 Circle Through Three Points(三角形外接圆)

    题目链接:http://poj.org/problem?id=1329 #include<cstdio> #include<cmath> #include<algorit ...

  7. 设置单网卡双ip

    环境如下: [root@localhost ~]# cat /etc/redhat-releaseCentOS Linux release 7.7.1908 (Core) 安装时选择的最小化安装 -- ...

  8. vue组件的inheritAttrs属性

    vue官网对于inheritAttrs的属性解释:如果你不希望组件的根元素继承特性,你可以在组件的选项中设置 inheritAttrs: false. 可能不是很好理解,我们可以举个例子来验证一下. ...

  9. 使ie6/7/8支持css3的方法

    使用PIE.htc让IE6\7\8支持CSS3部分属性 包括圆角,阴影,背景渐变等效果 下载地址 http://css3pie.com/download/ 需要注意几点的是 第一,pie是以相对页面h ...

  10. C语言之文件包含

    c = #include <stdio.h> #include "A.h" int main() { /******************************** ...