GCD - Extreme (II) UVA - 11426 数学】的更多相关文章

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…
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])…
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,…
题目大意: 累加从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(…
Given the value of N, you will have to find the value of G. The definition of G is given below:…
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…
[UVa11426]GCD - Extreme (II)(莫比乌斯反演) 题面 Vjudge 题解 这.. 直接套路的莫比乌斯反演 我连式子都不想写了 默认推到这里把.. 然后把\(ans\)写一下 \[ans=\sum_{d=1}^nd\sum_{i=1}^{n/d}\mu(i)[\frac{n}{id}]^2\] 令\(T=id\) 然后把\(T\)提出来 \[ans=\sum_{T=1}^n[\frac{n}{T}]^2\sum_{d|T}d\mu(\frac{T}{d})\] 后面那一堆…
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\),自己与自己…
/** 题目: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…
uva11424: 题目:给出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(…
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…
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 <…
题意: 求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 <…
题目链接: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…
题意:求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),这…
分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring> using namespace std;…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAgAElEQVR4nOzdPW7zvII/bG1gCi9gKq1ggHSnm0ZLSHOKabWCP5AdqJxigABPMaVXkOJ0A3gDwVSnMWYD3oPfgrj5MtSHJccME+W6ige+bX1QlKyH/JmhmgYAAAAAAAAAAAAA4Mf4l3/5l9pFAGCHrgAA/DS1m5AA7JEAGoASaveeAADYrHYTEoA9E…
discription 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 me…
题目链接: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…
题目大意:求gcd(1,2)+gcd(1,3)+gcd(2,3)+...+gcd(n-1,n) ----------------------------------------------------------------- 设f(i)=gcd(1,n)+...+gcd(n-1,n),则答案S(n)=f(2)+...+f(n) 如何求f 设g(n,i)表示满足gcd(x,n)=1且x<n的x个数,则f(n)=sum{i*g(n,i):i|n} gcd(x,n)=i的充要条件是x/i和n/i互质…
题意:求sum(gcd(i,j),1<=i<j<=n)1<n<4000001 思路: 1.建立递推关系,s(n)=s(n-1)+gcd(1,n)+gcd(2,n)+……+gcd(n-1,n); 2.设f(n)=gcd(1,n)+gcd(2,n)+……+gcd(n-1,n). gcd(x,n)=i是n的约数(x<n),按照这个约数进行分类.设满足gcd(x,n)=i的约束有g(n,i)个,则有f(n)=sum(i*g(n,i)). 而gcd(x,n)=i等价于gcd(x/…
题目链接 题意: 给定一个n, 求:GCD(1, 2) + GCD(1, 3) + GCD(2, 3) + …… + GCD(1, n) + GCD(2, n) + …… + GCD(n-1, n); 设f(n) = ΣGCD(i, n), i = 1, 2, 3, ... , n-1 本题即求:f(2) + f(3) + f(4) + ... + f(n) 设s(n) = f(2) + f(3) + f(4) + ... + f(n) 1) 令 d = GCD(x, n), d 是 x, n的…
https://cn.vjudge.net/problem/UVA-11426 题意:求 解题思路:我们可以定义一个变量dis[n],dis[n]意为1~(n-1)与n的gcd(最大公约数)的总和,那么可以得到ans[n]=ans[n-1]+dis[n],那么问题来了,如何求dis[n]呢?我们可以假设一个变量a[i],a[i]为gcd(n,m)==i   (1<=m<n)的个数,那么dis[n]=sum{a[i]*i}了,由gcd(n,m)=i得,gcd(n/i,m/i)=1,即dis[n]…
题目链接: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…
题面 莫反是不可能莫反的,这辈子都不可能莫反了 题目要求的是 \[ \sum\limits_{i=1}^n \sum\limits_{j=i+1}^n \gcd(i,j) \] 稍微变个亚子 \[ \sum\limits_{i=1}^n \sum\limits_{j=1}^{i-1} \gcd(i,j) \] 考虑求\(f(n)=\sum\limits_{i=1}^{n-1} \gcd(n,i)\) 首先\(\gcd(n,i) \mid n\),考虑枚举\(\gcd\)的值 \[ f(n)=\s…