题目链接: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. MyEclipse6.0中使用aptana插件,添加jquery提示功能

    MyEclipse6.0中使用aptana插件,添加jquery提示功能 第一:查看当前MyEclipse集成的eclipse的版本,, 查看路径    D:/MyEclipse 6.0/eclips ...

  2. 杂项-WebService:WebService

    ylbtech-杂项-WebService:WebService Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个 ...

  3. linux中export的作用

    设置环境变量. 为什么设置环境变量?---->全局使用. 不设置环境变量会怎么样?->只有当前shell中能够调用,其他的shell不能调用. 设置了之后呢?->全局都能调用.

  4. 最小生成树--Prim及Kruskal

    //prim算法#include<cstdio> #include<cmath> #include<cstring> #include<iostream> ...

  5. python将字典列表导出为Excel文件的方法

    将如下的字典列表内容导出为Excel表格文件形式: ​ 关于上图字典列表的写入,请参考文章:https://blog.csdn.net/weixin_39082390/article/details/ ...

  6. CF#537 C. Creative Snap /// DFS

    题目大意: 给定n k A B为位置长度 复仇者个数 两种花费 在一段为1~2^n的位置中 某些位置存在一些复仇者 求消灭所有复仇者的最小花费 对一段位置可以有两种处理方式 1.若该段长度至少为2 可 ...

  7. springboot + zipkin + mysql

    zipkin的数据存储可以存在4个地方: 内存(仅用于测试,数据不会持久化,zipkin-server关掉,数据就没有了) 这也是之前使用的 mysql 可能是最熟悉的方式 es Cassandra ...

  8. MVC--MVP?

    第一部分:什么是MVP?什么是MVC? 1.什么是MVP? M:数据层(数据库.网络.文件存储等等...) V:View和Activity和Fragment以及它们的子类 P:中介->Prese ...

  9. Flask理论基础(一)加载配置文件

    一.修改/新增配置项 1.使用配置文件 app.config.from_pyfile("config.cfg") 如上 config.cfg 可以是任意后缀的文本文件,需要与app ...

  10. 链表list

    Don't  lost link! list与vector不同之处在于元素的物理地址可以任意. 为保证对列表元素访问的可行性,逻辑上互为前驱和后继的元素之间,应维护某种索引关系.这种索引关系,可抽象地 ...