找新朋友

题解 欧拉函数

Problem Description

新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。

Input

第一行是测试数据的组数CN(Case number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。

Output

对于每一个N,输出一行新朋友的人数,这样共有CN行输出。

Sample Input

2

25608

24027

Sample Output

7680

16016

 1 #include<stdio.h>
 2 
 3 #include<math.h>
 4 
 5 
 6 
 7 int enlerFun(int n)
 8 
 9 {
10 
11 int count=n;
12 
13 int i=2;
14 
15 for(;i<=n;i++)
16 
17 if(n%i==0)
18 
19 {
20 
21 count-=count/i;
22 
23 while(n%i==0)
24 
25 n/=i;
26 
27 }
28 
29 return count;
30 
31 }
32 
33 
34 
35 int main()
36 
37 {
38 
39 int cn,n;
40 
41     scanf("%d",&cn);
42 
43 while(cn--)
44 
45 {
46 
47 int count=0;
48 
49 scanf("%d",&n);
50 
51 count=enlerFun(n);
52 
53 printf("%d
",count);
54 
55 }
56 
57 return 0;
58 
59 }
原文地址:https://www.cnblogs.com/awsent/p/4267110.html