【GDSOI 2016】第一题 互补约数
来源:互联网 发布:intel edison linux 编辑:程序博客网 时间:2024/04/30 11:31
Description
简化题意:求
Input
输入包含一行,一个正整数 n。
Output
输出只有一行, F(n)。
Sample Input
Sample Input1:
10
Sample Input2:
1000
Sample Output
Sample Output1:
32
Sample Output2:
12776
Data Constraint
Solution
两个sigma外加gcd,直接考虑反演
这里是枚举i和i的约数,我们转换为枚举i和i的倍数
套路反演
设
设
反演得
设
将
为了方便预处理,设
我们知道,如果gcd(x,y)为T的倍数,那么x,y也是T的倍数
那么
因为
所以
枚举
所以
于是,你会惊奇的发现,答案变成了
ans=∑T=1n√g[T]∗a(t)
很简单对吧
但还是过不了
求g[t]的时候用分块优化一下,而t本身不能分块(为什么?)
时间复杂度
Code
#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#define ll long long#define fo(i,a,b) for(int i=a;i<=b;i++)#define N 401000using namespace std;ll n,mu[N],a[N],bz[N],s[N];int main(){ freopen("gcd.in","r",stdin);freopen("gcd.out","w",stdout); scanf("%lld",&n); ll m=sqrt(n); mu[1]=1; fo(i,2,m) { if(!bz[i]) s[++s[0]]=i,mu[i]=-1; fo(j,1,s[0]) { int k=i*s[j]; if(k>m) break; bz[k]=1; if(i%s[j]==0) {mu[k]=0;break;} mu[k]=-mu[i]; } } fo(i,1,m) fo(j,1,m/i) a[i*j]+=j*mu[i]; ll ans=0; for(ll t=1;t<=m;t++) { ll jy=0,q=n/(t*t); for(ll x=1,y=1;x<=q;y=x+1,x=min((q/(q/y)),q)) { jy+=(x-y+1)*(q/x); if(x>=q) break; } ans+=(jy*a[t]); } printf("%lld",ans);}
1 0
- 【GDSOI 2016】第一题 互补约数
- GDOI2016 之 GDSOI 第一题 互补约数
- 【GDSOI 2016】互补约数
- 【GDSOI 2016】互补约数
- GDSOI 2016 T1 互补约数
- [JZOJ4496] 【GDSOI 2016】互补约数
- 【JZOJ 4496】【GDSOI 2016】第一题 互补约数 (两种解法)
- 互补约数(GCD)续
- 【GDOI2016】互补约数 题解
- GDSOI 2016 T2 星际穿越
- 【GDSOI 2017】【JZOJ 5107】中学生数据结构题
- GDSOI模拟4.13总结
- GDOI&&GDSOI总结
- 欧拉工程第12题 第一个拥有超过500个约数的三角形数是多少
- 互补滤波
- 互补滤波器
- 互补滤波器
- 互补滤波器
- java中的 FileWriter类 和 FileReader类的一些基本用法
- WC集训总结
- fabric0.6同步流程
- python+testlink+jenkins集成测试自动化
- OJ 1901: 简单密码破解
- 【GDSOI 2016】第一题 互补约数
- 内存寻址
- PAT甲级1049
- Spring boot 性能优化
- Nginx源码阅读(ngx_queue_t)
- 【Linux】教你如何玩转MAC地址
- 二叉树的层次遍历
- 值得推荐的C/C++框架和库(深度好文)
- 2017.1.21【初中部 GDKOI】模拟赛B组 逻辑的连通性 题解