CF1174C Ehab and a Special Coloring Problem(数论)
做法
与\(x\)互质的数填不同的数,把有向关系表示出来,发现边数是不能承受的
反过来想,成倍数关系填相同的数,把这些数想象成一条链,而这条链开始的数一定是质数,\(\sum\limits_{prime_i}\frac{n}{prime_i}\)是可以承受的
把这条链的点赋一个相同的值
Code
#include<bits/stdc++.h>
using namespace std;
typedef int LL;
const LL maxn=1e6+9;
inline LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3)+(x<<1)+c-'0'; c=getchar();
}return x*f;
}
LL n,ans,tot;
LL visit[maxn],prime[maxn],phi[maxn],a[maxn];
int main(){
n=Read();
phi[1]=1;
for(LL i=2;i<=n;++i){
if(!visit[i]){
prime[++tot]=i;
phi[i]=i-1;
}
for(LL j=1;prime[j]*i<=n;++j){
visit[prime[j]*i]=true;
if(i%prime[j]==0){
phi[prime[j]*i]=phi[i]*prime[j];
break;
}else
phi[prime[j]*i]=phi[i]*phi[prime[j]];
}
}
for(LL i=1;i<=tot;++i){
LL now(prime[i]);
a[now]=i;
LL val(now<<1);
while(val<=n){
a[val]=i;
val+=now;
}
}
for(LL i=2;i<=n;++i) printf("%d ",a[i]);
return 0;
}
CF1174C 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 ...
- Codeforces 1174C Ehab and a Special Coloring Problem
题目链接:http://codeforces.com/problemset/problem/1174/C 题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数 ...
- 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 ...
- [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& ...
- Codeforces 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...
- 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 ...
- 题解-Ehab's REAL Number Theory Problem
Ehab's REAL Number Theory Problem 前置知识 质数 分解质因数 无向无权图最小环<讲> Ehab's REAL Number Theory Problem/ ...
- CF1174E Ehab and the Expected GCD Problem(DP,数论)
题目大意:对于一个序列,定义它的价值是它的所有前缀的 $\gcd$ 中互不相同的数的个数.给定整数 $n$,问在 $1$ 到 $n$ 的排列中,有多少个排列的价值达到最大值.答案对 $10^9+7$ ...
随机推荐
- ubuntu环境下pycharm编译程序import包出错:ImportError: dynamic module does not define init function (init_caffe)
出错原因是因为pycharm中的python版本不对,比如程序为2.7版本,但是pycharm编解释器为python3,导致出错,去setting改一下版本就行:pycharm>file> ...
- linux 系统运维工具13款
1. 查看进程占用带宽情况 - Nethogs Nethogs 是一个终端下的网络流量监控工具可以直观的显示每个进程占用的带宽. 下载:http://sourceforge.net/projects/ ...
- GoAccess 视图化access.log 日志
1.安装GoAccess 工具可以直接使用 apt-get install goaccess 2.使用goaccess命令将日志生成html文件 goaccess 日志路径 -o 输出HTML的路径 ...
- Git Git 已被其他开发删除的远程分支,本地依旧显示,如何删除?
- [dev][ipsec] 基于路由的VPrivateN
VPrivateN的配置分两个模式 1. 基于策略的VPrivateN ( policy based) 2. 基于路由的VPrivateN (route based) 以strongswan为例, 在 ...
- 《Python编程:从入门到实践》第三章 列表简介 习题答案
#3.1 names=['lpr','tjl','gnl','by','dqy']; print(names[0]); print(names[1]); print(names[2]); print( ...
- ubuntu---记录.动态库默认路径的踩坑
发现这个问题,还是经过一个报错问题卡了好多天,然后请求好多人的支援,最后个人的疑问:为什么明明指明了路径,生成 .SO 没有问题,在调用.SO 就有问题,报错各种找不到函数或者未定义,然后把缺的 *. ...
- Eclipse安装scala插件
1.下载插件 http://scala-ide.org/download/current.html 2.将下载的压缩包解压,拷贝到eclipse\dropins目录下 3.启动eclipse,安装 ...
- CPC组队赛训练记录
2017中国大学生程序设计竞赛-哈尔滨站 (rank 39)solved 4 补 1 2018 CCPC 吉林 solved 5 2017CCPC秦皇岛 solved 4 待补题 2017ACM/IC ...
- What Does Reconciliation Mean in Accounting
Account reconciliation is the process of comparing transactions you have recorded using internal rec ...