题目链接: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. 误将SELINUXTYPE看成SELINUX后,将其值改为disabled。导致操作系统服务启动,无法进入单用户模式

    环境:Redhat 6.4 ORACLE11g RAC 在安装ORACLE11g之前需要关闭操作系统的防火墙和SELinux. 1.关闭防火墙:iptables -F————————————清除防火墙 ...

  2. 执行 systemctl start firewalld 命令后出现Failed to start firewalld.service: Unit is masked

    firewalld服务被锁定,不能添加对应端口 执行命令,即可实现取消服务的锁定 # systemctl unmask firewalld 下次需要锁定该服务时执行 # systemctl mask ...

  3. [7.19NOIP模拟测试6]失恋三连(雾 题解

    题面(加密) 不得不说这次的题除了引起单身汪极度不适之外还是出的很有水平的…… A. 很好的dp题 模型非常简单,如果数据范围足够友好的话就是一道dp入门题 30%: 我们可以设$dp[i][j]$为 ...

  4. phpstrom中Terminal窗口打开

    Terminal窗口其实就是cmd窗口

  5. tp U函数 logs

    注意 U 函数 项目今天已经搞定了本以为可以上线了没问题了,但是 当我把tp调试模式关闭后:      define('APP_DEBUG',false); 页面完全加载不出来,于是开启:  'SHO ...

  6. ThinkPHP学习(二)理清ThinkPHP的目录结构及访问规则,创建第一个控制器

    ThinkPHP的目录结构 回顾上一篇的安装目录: 目录对应关系 F:\\PHP├─index.php       入口文件├─README.md       README文件├─Applicatio ...

  7. ()centos7 安装python36

    centos7 默认安装 python2.7 1.先安装python36和对应pip yum install python-pip #安装python2的pip yum install python3 ...

  8. 机器学习基石笔记:Homework #4 Regularization&Validation相关习题

    原文地址:https://www.jianshu.com/p/3f7d4aa6a7cf 问题描述 程序实现 # coding: utf-8 import numpy as np import math ...

  9. vue组件通信之父组件主动获取子组件数据和方法

    ref 可以用来获取到dom节点,如果在组件中应用,也可以用来获取子组件的数据和方法. 比如,我定义了一个home组件,一个head组件,home组件中引用head组件. 此时,home组件是head ...

  10. Git 学习第一天

    本文是根据廖雪峰老师的git教程记录的学习笔记,特此说明,原教程链接https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c ...