题目大意: 累加从1到n,任意两个数的gcd(i,j)(1=<i<n&&i<j<=n). 题解:假设a<b,如果gcd(a,b)=c.则gcd(a/c,b/c)=1.也就是说a/c和b/c互质,而与a/c互质的数一共有oula(a/c)个,也就是说这里的b/c一共有oula(a/c)种选择,同理,gcd(a,b)=c,a的选择就会有,oula(b/c)种. 所以 gcd(x,y)=1  ,枚举每一个x,然后在枚举x的k倍,答案就是ans[x*k]+=oula(…
Code: #include<cstdio> using namespace std; const int maxn=4000005; const int R=4000002; const int N=4000002; long long sumv[maxn],f[maxn]; int phi[maxn],prime[maxn],vis[maxn]; void solve(){ phi[1]=1; int cnt=0; for(int i=2;i<=R;++i){ if(!vis[i])…
题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x有phi(n/i)个,其中Phi为欧拉函数. 所以枚举i和i的倍数n,累加i * phi(n/i)即可. #include <cstdio> typedef long long LL; ; ]; LL f[maxn + ]; void phi_table() { phi[] = ; ; i <…
G(i) = (gcd(1, i) + gcd(2, i) + gcd(3, i) + .....+ gcd(i-1, i)) ret = G(1) + G(2) + G(3) +.....+ G(n); 对于gcd(x,i),我们设gcd(x,i) = m 即x和i的最大公约数为m  则x/m 和 i/m 互质 然后我们求出于i/m互质的有多少个 是不是就是求出了与i最大公约数为m的有多少个..用欧拉函数既能求出个数  ...即为phi(i/m)个  用双重循环  外层循环为m内层循环为i,…
题意:给你一个数N,求N以内和N的最大公约数的和 解题思路: 一开始直接想暴力做,4000000的数据量肯定超时.之后学习了一些新的操作. 题目中所要我们求的是N内gcd之和,设s[n]=s[n-1]+gcd(1,n)+gcd(2,n)+gcd(3,n)+gcd(4,n)....... 再设f[n]=gcd(1,n)+gcd(2,n)+gcd(3,n)+gcd(4,n).......; 思考一下,假设gcd(x,n)=ans,ans便是x和n的最大公约数,那么有几个ans我们将某ans的个数su…
题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1]+f[2]+f[3]+-+f[n] sum[n-1]=f[1]+f[2]+-+f[n-1] sum[n]=sum[n-1]+f[n] 所以我们求出f[n]的值即可 1~n-1与 n 的最大公约数暴力来求肯定超时: 设gcd(x,n)=i 表示 n 和 x 的最大公约数为i,那么gcd( x/i ,…
Given the value of N , you will have to nd the value of G . The de nition of G is given below: G = i<N ∑ i =1 j N ∑ j = i +1 GCD ( i; j ) Here GCD ( i; j ) means the greatest common divisor of integer i and integer j . For those who have trouble unde…
Given the value of N, you will have to find the value of G. The definition of G is given below:…
/** 题目:GCD - Extreme (II) 链接:https://vjudge.net/contest/154246#problem/O 题意: for(i=1;i<N;i++) for(j=i+1;j<=N;j++) { G+=gcd(i,j); } 思路: 设f[n] = gcd(1,n)+gcd(2,n)+gcd(3,n)+...+gcd(n-1,n); s[n] = f[1]+f[2]+...+f[n]; 则:s[n] = f[n]+s[n-1]; f[n]的约数个数一般少于n…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/article/details/5787722 题意 a,b,c,d,k五个数,a与c可看做恒为1,求在a到b中选一个数x,c到d中选一个数y,使得gcd(x,y)等于k,求x和y有多少对. 首先可以想到选取的必是k的倍数,假设是x和y倍,则x和y一定是互质的在,那么就变成了求1到b/k和1到d/k的之…