题目链接: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. css 导航样式

    html  结构 <div class="nav-menu float-r"> <ul class="menu-item"> <l ...

  2. 四:RF框架appium工具之xpath定位

    XPATH定位方法具体的学会,还是在今年1月份,以前运用的都不熟练. 这个定位神器是一定要掌握的,不然有你抓狂的时候. 第一要掌握它的书写格式,这个好上手. 第二要掌握它的具体用法.这个就要多练习了, ...

  3. java.io.IOException: Could not find resource SqlMapConfig.xml

    java.io.IOException: Could not find resource SqlMapConfig.xml 创建mybatis工程时遇到的问题 问题的来源:当我们在项目中和src同级的 ...

  4. PHP面试 PHP基础知识 五(自定义函数和内部函数)

    自定义函数 变量的作用域和静态变量 变量的作用域:变量的作用域也成为变量的范围,变量的范围即它定义上的上下文背景(也就是它生效的范围). 大部分的PHP变量只有一个单独的范围.这个单独的范围跨度同样包 ...

  5. UDP 两种丢包处理策略:丢包重传(ARQ) 和 前向纠错(FEC)

    目录 1. 两种丢包处理策略 2. 前向纠错(FEC) 3. 丢包重传(ARQ) [参考文献] 1. 两种丢包处理策略 为了保证实时性,通常适应UDP协议来针对RTP数据进行传输,而UDP无法保证数据 ...

  6. 4.2.1 Vector bit-select and part-select addressing

    Frm:IEEE Std 1364™-2001, IEEE Standard Verilog® Hardware Description Language Bit-selects extract a ...

  7. 洛谷 P4173 残缺的字符串 (FFT)

    题目链接:P4173 残缺的字符串 题意 给定长度为 \(m\) 的模式串和长度为 \(n\) 的目标串,两个串都带有通配符,求所有匹配的位置. 思路 FFT 带有通配符的字符串匹配问题. 设模式串为 ...

  8. umount - 卸载文件系统

    总览 umount [-hV] umount -a [-nrv] [-t vfstype] umount [-nrv] device | dir [...] 描述 umount 可以卸除当前挂载在文件 ...

  9. volatile的使用及其原理

    1. volatile的作用 相比Sychronized(重量级锁,对系统性能影响较大),volatile提供了另一种解决 可见性和有序性 ???问题的方案.对于原子性,需要强调一点,也是大家容易误解 ...

  10. sqlmap结合burpsuite对post请求进行注入测试

    1. 浏览器打开目标地址 http://testasp.vulnweb.com/Login.asp 2. 配置burp代理(127.0.0.1:8080)以拦截请求 3. 点击login表单的subm ...