传送门 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 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…
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,…
思路:首先给出几个结论: 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&…
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). 知…
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2*f[i]-1. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <stack> #include <vector> #inclu…
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][Status][Discuss] Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一个整数,为N. Output 一个整数,为所求的答案. Sample Inp…
A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2478 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 &l…
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][Status][Discuss] Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一个整数,为N. Output 一个整数,为所求的答案. Sample Inp…