Farey Sequence Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are Input There are several test cases. Each test case has only one line, which contains a positive integer n (2 <= n <= 106). There are no blank lines between cases. A line with a single 0 terminates the input. Output For each test case, you should output one line, which contains N(n) ---- the number of terms in the Farey sequence Fn. Sample Input Sample Output Source POJ Contest,Author:Mathematica@ZSU |
Time Limit: 1000MS | | Memory Limit: 65536K |
Total Submissions: 18838 | | Accepted: 7581 |
算法分析:
裸的欧拉函数求和问题,最后用long long 保存
代码实现