spoj 3871 gcd extreme】的更多相关文章

3871. GCD Extreme Problem code: GCDEX Given the value of N, you will have to find the value of G. The meaning of G is given in the following code G=0; for(k=i;k< N;k++) for(j=i+1;j<=N;j++) { G+=gcd(k,j); } /*Here gcd() is a function that finds the g…
题目大意给出一个n,求sum(gcd(i,j),<i<j<=n); 可以明显的看出来s[n]=s[n-]+f[n]; f[n]=sum(gcd(i,n),<i<n); 现在麻烦的是求f[n] gcd(x,n)的值都是n的约数,则f[n]= sum{i*g(n,i),i是n的约数},注意到gcd(x,n)=i的 充要条件是gcd(x/i,n/i)=,因此满足条件的 x/i有phi(n/i)个,说明gcd(n,i)=phi(n/i). f[n]=sum{i*phi(n/i),=&…
转载请注明出处: 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…
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)…
[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…
题目: SPOJ-GCDEX (洛谷 Remote Judge) 分析: 求: \[\sum_{i=1}^{n}\sum_{j=i+1}^{n}gcd(i,j)\] 这道题给同届新生讲过,由于种种原因只讲了 \(O(n)\) 预处理欧拉函数 \(O(n)\) 查询的暴力做法,顺带提了一句 "这题能根号查询" 被教练嘴了 QAQ .以及小恐龙给我说有 \(O(n\log n)\) 预处理 \(O(1)\) 查询的另一种写法. 重点是前几天某学长讲课讲这道题,才知道有 \(O(n)\) 预…
题目大意:求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互质…
题目:给出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…
题意: 求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…
题意:求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的…
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(…
Description Given the value of N, you will have to find the value of G. The meaning of G is given in the following code G=0; for(i=1;i&ltN;i++) for(j=i+1;j<=N;j++) G+=gcd(i,j); /*Here gcd() is a function that finds the greatest common divisor of th…
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]…
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,…
思路: 虽然看到题目就想到了用欧拉函数做,但就是不知道怎么做... 当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…
题目链接: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…
题意:给一个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 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…
题目链接:https://vjudge.net/problem/UVA-11426 题目大意: 给出整数n∈[2,4000000],求解∑gcd(i,j),其中(i,j)满足1≤i<j≤n. 的确没有想到是欧拉函数,这怎么会想到欧拉函数呢?  又不是要我们求所有gcd为1的个数  那些gcd不为1的怎么办呢?  当时怎么就没想到呢  除过去不就变为1了吗  自己是真的菜... 还是要多做题,把思维开阔起来!!! 思路在代码中  直接看代码: /** 欧拉函数三个性质 是素数的话 欧拉函数值等于它…
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…
<训练指南>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…
题目链接: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…
直接两重循环O(n^2)算gcd……未免太耗时 枚举因数a和a的倍数n,考虑gcd(i,n)==a的i数量(i<=n) 由于gcd(i,n)==a等价于gcd(i/a,n/a)==1,所以满足gcd(i,n)==a的数有phi[n/a]个 打出欧拉函数表,枚举因数,计算出每个n的f[n]=gcd(1,n)+gcd(2,n)+gcd(3,n)+...+gcd(n-1,n) 然后求f[n]的前缀和,回答询问. /*by SilverN*/ #include<iostream> #includ…
易得 $\sum\limits_{g=1}^{n} g \sum\limits_{k=1}^{n} \mu(k) \lfloor\frac{n}{gk}\rfloor \lfloor\frac{n}{gk}\rfloor $ 记 \(T=gk\) 枚举 \(T\) ,注意这里既然满足 \(T=gk\) 要保证两个乘起来确实是 \(T\) ,选择把 \(k\) 换成 $\frac{T}{g} $ . $\sum\limits_{T=1}^{n} \lfloor\frac{n}{T}\rfloor…
You are given N(1<=N<=100000) integers. Each integer is square free(meaning it has no divisor which is a square number except 1) and all the prime factors are less than 50. You have to find out the number of pairs are there such that their gcd is 1…