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$ ...
随机推荐
- C# ObservableCollection两个字段排序的情况
相对于System.Linq的OrderBy及OrderByDescending方法,调用后产生IOrderedEnumberable对象,这个对象为排序后的返回值,但原对象未发生变化. 试想,有这种 ...
- The Art Of Loving
The Art Of Loving 来源 https://www.zhihu.com/question/23720541 ----------------------------- 茫然的蒲公英 有书 ...
- 8. Java的运算符
计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量. 我们把运算符具体分为:算数运算符,比较运算符,逻辑运算符,位运算符,赋值运算符,条件运算符,i ...
- mysql建表常用命令
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RD ...
- vue中将时间戳转换为YYYY-MM-dd hh:mm格式时间的组件
首先我们可以使用vue中的过滤方法将数据变成另一个格式 // html <span class="rate-time">{{rating.rateTime | form ...
- 发现一个对列排版挺好用的命令:column
help [root@hdpool1 tmp]# column -h Usage: column [options] [file ...] Options: -c, --columns <wid ...
- js回调函数的理解
js回调函数(callback)理解 Mark! 讲之前说一句 function say(){ alert(,,,,,,,,) } var say=function (){ alert(,,,,,,, ...
- Python_关键字列表
1.Python关键字列表
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- 运维CMDB建设思路
在我们日常的运维工作中,面对着大量的基础设施和软件服务,该如何管理?这个管理的原则又是什么?粒度该如何控制?我们是否可以建立一个统一的标准模型来管理以上对象?管理过程中,如何降低人力成本?资源对象的生 ...