题目链接: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…
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) 的值…
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…
分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring> using namespace std;…
题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此题和UVA 11426 一样,不过n的范围只有20000,但是最多有20000组数据. 当初我直接照搬UVA11426,结果超时,因为没有预处理所有的结果(那题n最多4000005,但最多只有100组数据),该题数据太多了额... 思路:令sum(n)=gcd(1,n)+gcd(2,n)+...+g…
UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13015 143295493160 Solution 这道题我用莫比乌斯反演和欧拉函数都写了一遍,发现欧拉函数比莫比乌斯反演优秀? 求所有\(gcd=k\)的数对的个数,记作\(f[k],ans=\sum_{i=1}^{n}(f[i]-1)\),为什么还要-1,我们注意到\(j=i+1\),自己与自己…
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=473&problem=2421&mosmsg=Submission+received+with+ID+13800900 Given the value of N, you will have to find the value of G. The definition…
题目链接:https://vjudge.net/problem/UVA-11426 题意: 求 ∑ gcd(i,j),其中 1<=i<j<=n . 题解:1. 欧拉函数的定义:满足 0<x<n 且 gcd(x,n) = 1 的x有euler[n]个. 2. 可以推论出:满足 0<2*x<2*n 且 gcd(2*x,2*n) = 2 的2*x同样有euler[n]个,推向一般:满足 0<k*x<k*n 且 gcd(k*x,k*n) = k 的k*x有eu…
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)…