2818: Gcd
来源:互联网 发布:凡科互动 游戏源码 编辑:程序博客网 时间:2024/06/07 02:00
2818: Gcd
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4048 Solved: 1784
[Submit][Status][Discuss]
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
Source
湖北省队互测
#include<iostream>#include<cstdio>#include<queue>#include<vector>#include<bitset>#include<algorithm>#include<cstring>#include<map>#include<stack>#include<set>#include<cmath>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 1E7 + 10;typedef long long LL;int tot,prime[maxn],mu[maxn],sum[maxn];bool not_prime[maxn];LL ans,n;int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n; mu[1] = 1;for (int i = 2; i <= n; i++) {if (!not_prime[i]) {mu[i] = -1; prime[++tot] = i;}for (int j = 1; j <= tot; j++) {int Nex = i*prime[j];if (Nex > n) break;not_prime[Nex] = 1;mu[Nex] = mu[prime[j]]*mu[i];if (i % prime[j] == 0) {mu[Nex] = 0; break;}} }for (int i = 1; i <= tot; i++)for (int j = 1; ; j++) {int Nex = j*prime[i];if (Nex > n) break;sum[Nex] += mu[Nex/prime[i]];}for (LL i = 1; i <= n; i++) ans += 1LL*sum[i]*(n/i)*(n/i);cout << ans;return 0;}
讲道理这个式子单词计算复杂度可以降成根号来回答多组询问。。bulabulabula
0 0
- 2818: Gcd
- 2818: Gcd
- BZOJ 2818 gcd
- 新视野OJ 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
- HYSBZ 2818 Gcd
- bzoj 2818: Gcd
- BZOJ 2818 Gcd
- _ADD_COL_OPTIM_ENABLED参数
- JPush推送服务集成
- poj 1128 Frame Stacking(拓扑排序+DFS(递归))
- jquery grid表格checkbox的关联勾选与取消
- 使用thinkphp+dwz博客总结
- 2818: Gcd
- Java获取当前日期时间
- 抛弃mysql模糊查询,使用sphinx做专业索引
- poj 3122 Pie
- Interpolation Tricks
- 大数据量的算法面试题
- printf 的宏定义版本
- CSS3 box-shadow
- 数据结构实验之查找四:二分查找