sgu102 Coprimes

102. Coprimes

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

 

For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime if (and only if) their greatest common divisor is 1. (i.e. A and B are coprime iff gcd(A,B) = 1).

 

Input

Input file contains integer N.

 

Output

Write answer in output file.

 

Sample Input

9

Sample Output

6

题意:对于数N,求不大于N的正整数中,与N互质的数有多少个。

思路1:因为N的数值范围比较小,最简单的方法是使用枚举法,直接枚举所有不大于N的数,求gcd,统计个数。方法比较简便。这样要注意一个小小的bug,1和1也是互质的,因为他们的最大公约数是1。因为这个wa了两次T T。

思路2:用欧拉函数求解。

posted @ 2015-03-26 14:49  一个大叔  阅读(106)  评论(0编辑  收藏  举报