下面是小编收集整理的POJ 2478Farey Sequence(筛选法求欧拉函数),本文共2篇,供大家参考借鉴,希望可以帮助到有需要的朋友。

篇1:POJ 2478Farey Sequence(筛选法求欧拉函数)
Farey SequenceTime Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2478 Appoint description:
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 areF2 = {1/2}
F3 = {1/3, 1/2, 2/3}
F4 = {1/4, 1/3, 1/2, 2/3, 3/4}
F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5}
You task is to calculate the number of terms in the Farey sequence Fn.
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
23450
Sample Output
1359
题意:给定一个数n,求小于或等于n的数中两两互质组成的真分数的个数,
POJ 2478Farey Sequence(筛选法求欧拉函数)
,
思路:这个博客有关于这道题的推理---->点击打开链接
#include
篇2:POJ 2407Relatives(求一个整数的欧拉函数值)
RelativesTime Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2407 Appoint description:
Description
Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x >1, y >0, z >0 such that a = xy and b = xz.Input
There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.Output
For each test case there should be single line of output answering the question posed above.Sample Input
7120
Sample Output
64
题意:给一个数n,求出不大于n且与n互素的数的个数,
POJ 2407Relatives(求一个整数的欧拉函数值)
,
#include
文档为doc格式