bzoj 2818: Gcd
来源:互联网 发布:计算机加密软件 编辑:程序博客网 时间:2024/05/17 06:54
Description
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的
数对(x,y)有多少对.
Input
一个整数N
Output
如题
Sample Input
4
Sample Output
4
HINT
hint
对于样例(2,2),(2,4),(3,3),(4,2)
1<=N<=10^7
数论题心累。。总之就是各种变换。。
见http://wzimpha.sinaapp.com/archives/499#comment-41
#include<cstdio>#include<string>#include<cstring>using namespace std;int mu[10000001],prime[10000001];int g[10000001];int sum[10000001]; bool check[10000001]; int n;int tot;inline void findmu(){ memset(check,false,sizeof(check)); mu[1]=1; int i,j; for(i=2;i<=n;i++) { if(!check[i]) { tot++; prime[tot]=i; mu[i]=-1; g[i]=1; } for(j=1;j<=tot;j++) { if(i*prime[j]>n) break; check[i*prime[j]]=true; if(i%prime[j]==0) { mu[i*prime[j]]=0; g[i*prime[j]]=mu[i]; break; } else { mu[i*prime[j]]=-mu[i]; g[i*prime[j]]=mu[i]-g[i]; } } } for(i=1;i<=n;i++) sum[i]=sum[i-1]+g[i];}int main(){ scanf("%d",&n); findmu(); int d,j=0; long long ans=0; for(d=1;d<=n;d=j+1) { j=n/(n/d); ans+=(long long)(sum[j]-sum[d-1])*(n/d)*(n/d); } printf("%lld\n",ans); return 0;}
0 0
- BZOJ 2818 gcd
- BZOJ 2818 Gcd
- 【BZOJ 2818】 gcd
- bzoj 2818: Gcd
- BZOJ 2818: Gcd
- BZOJ 2818: Gcd
- 【BZOJ 2818】Gcd
- bzoj 2818: Gcd
- Gcd [Bzoj 2818]
- 【BZOJ 2818】Gcd
- 【BZOJ】2818 Gcd
- BZOJ 2818 Gcd
- bzoj 2818: Gcd
- BZOJ 2818 Gcd
- bzoj 2818 Gcd
- [bzoj 2818]Gcd
- BZOJ 2818——Gcd
- BZOJ 2818: Gcd 线形筛
- 3ds max 扫盲
- POJ 2513 Colored Sticks (Trie字典树+欧拉通路+并查集) 解题报告
- 【软件工程】关于软件工程里需要熟悉的一些基本问题的讨论(一)
- Android学习之SQLite练习(一)
- 配置pydot环境
- bzoj 2818: Gcd
- PyMel技术集锦
- 我的第一个c++
- python中的函数
- HTTP Basic Authentication认证的资源的C#实现
- nyoj 79 拦截导弹
- Linux中weblogic中axis.jar的冲突的解决办法
- 如何成为数据科学家( http://gkkgo.com/guide/44)
- Python--垃圾回收机制