poj 2480 Longge's problem】的更多相关文章

传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2416 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms.…
Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i,…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<algorithm> #include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; <<)+; ll n; int main() {…
Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. …
题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因如下:1到n中有m个数字和n拥有公共的最大因子p,那么就需要把m*p加入答案中.问题是如何计算m的个数.因为假设某个数i与n的最大公约数为p,那么gcd(i,n) = p,可以得到gcd(i/p,n/p)=1.也就是说,有多少个i,就有多少个i/p与n/p互质.那么显然m即为n/p的欧拉函数φ(n/p). 知…
思路:首先给出几个结论: 1.gcd(a,b)是积性函数: 2.积性函数的和仍然是积性函数: 3.phi(a^b)=a^b-a^(b-1); 记 f(n)=∑gcd(i,n),n=p1^e1*p2^e2……; 则 f(n)=∑d*phi(n/d) (d是n的约数)           =∑(pi*ei+pi-ei)*pi^(ei-1). 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include&…
/** 大意: 计算f(n) = ∑ gcd(i, N) 1<=i <=N. 思路: gcd(i,x*y) = gcd(i,x) * gcd(i, y ) 所以gcd 为积性函数 又因为积性函数的和函数 也是积性函数(具体数学,了解即可) f(n) = f(p1^a1 * p2^a2 * p3^a3*......* pn^an ) = f(p1^a1) * f(p2^a2) * f(p3* a3) ...... 现在我们先单独考虑一个 f(p1^a1) f(p^k)=1*φ(p^k)+ p*φ…
题目来源:id=2480" style="color:rgb(106,57,6); text-decoration:none">POJ 2480 Longge's problem 题意:求i从1到n的gcd(n, i)的和 思路:首先假设m, n 互质 gcd(i, n*m) = gcd(i, n)*gcd(i, m) 这是一个积性函数积性函数的和还是积性函数 由欧拉函数知识得 phi(p^a) = p^a - p^(a-1) p是素数 a是正整数 得到终于答案f(n)…
题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d | n}phi(n / d) * d ,后者是积性函数),能够这么解释:当d是n的因子时,设1至n内有a1,a2,..ak满足gcd(n,ai)==d,那么d这个因子贡献是d*k,接下来证明k=phi(n/d):设gcd(x,n)==d,那么gcd(x/d,n/d)==1,所以满足条件的x/d数目为phi(…