UVa 11426 - GCD - Extreme (II)】的更多相关文章

UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gcd(1, n) + gcd(2, n) + ... + gcd(n - 1, n).这种话,就能够得到递推式S(n) = f(2) + f(3) + ... + f(n) ==> S(n) = S(n - 1) + f(n);. 这样问题变成怎样求f(n).设g(n, i),表示满足gcd(x, n)…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Problem JGCD Extreme (II)Input: Standard Input Output: Standard Output Given the value of N, you will have to find the value of G. The definition of G is given below: Here GCD(i,j) means the…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2421 代码及其注释: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <…
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中1<=i <j <n. 要是求gcd(n , x) = y的个数的话,那么就是求gcd(n/y , x/y) = 1的个数,也就是求n/y的欧拉函数.这里先预处理出欧拉函数,然后通过类似筛法的技巧筛选出答案累加起来. #include <iostream> #include &l…
思路: 虽然看到题目就想到了用欧拉函数做,但就是不知道怎么做... 当a b互质时GCD(a,b)= 1,由此我们可以推出GCD(k*a,k*b)= k.设ans[i]是1~i-1与i的GCD之和,所以最终答案是将ans[0]一直加到ans[n].当 k*i==j 时,ans[j]=k*euler[i]. 看完题解瞬间领悟:神奇海螺 突然忘记欧拉函数是什么:欧拉函数 代码: #include<cstdio> #include<cstring> #include<cstdlib…
Given the value of N, you will have to find the value of G. The definition of G is given below:Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation notation, the meaning of G i…
题意:给一个N,和公式 求G(N). 分析:设F(N)= gcd(1,N)+gcd(2,N)+...gcd(N-1,N).则 G(N ) = G(N-1) + F(N). 设满足gcd(x,N) 值为 i 的且1<=x<=N-1的x的个数为 g(i,N). 则F(N)  = sigma{ i * g(i,N) }. 因为gcd(x,N) == i 等价于 gcd(x/i, N/i)  == 1,且满足gcd(x/i , N/i)==1的x的个数就是 N/i 的欧拉函数值.所以g(i,N) 的值…
<训练指南>p.125 设f[n] = gcd(1, n) + gcd(2, n) + …… + gcd(n - 1, n); 则所求答案为S[n] = f[2]+f[3]+……+f[n]; 求出f[n]即可递推求得S[n]:S[n] = S[n - 1] + f[n]; 所有gcd(x, n)的值都是n的约数,按照约数进行分类,令g(n, i)表示满足gcd(x, n) = i && x < n 的正整数x的个数,则f[n] = sum{ i * g(n, i) | n…
Given the value of N, you will have to find the value of G. The definition of G is given below:G =i<N∑i=1j∑≤Nj=i+1GCD(i, j)Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation no…
题意:求sum(gcd(i,j),1<=i<j<=n). 思路:首先能够看出能够递推求出ans[n],由于ans[n-1]+f(n),当中f(n)表示小于n的数与n的gcd之和 问题转化为了求f(n),由于小于n的数与n的gcd一定是n的因数, 所以f(n)能够表示为sum(i)*i,当中sum(i)表示全部和n的gcd为i的数的数量,我们要求满足gcd(a, n) = i,的个数,能够转化为求gcd(a/i, n/i) = 1的个数, 于是能够发现sun(i) = phi(n/i),这…