hdu 1286 找新朋友 (欧拉函数)

找新朋友

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6952    Accepted Submission(s): 3612


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
 

 

Author
SmallBeer(CML)
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1787 3792 1397 1299 1573 
 

 入门模板题:

 

 1 #include<stdio.h>
 2 int erlar(int n)
 3 {
 4     int ret=1;
 5     for(int i=2;i*i<=n;i++){
 6         if(n%i==0){
 7             n/=i,ret*=i-1;
 8             while(n%i==0){
 9                 n/=i,ret*=i;
10             }
11         }
12     }
13     if(n>1) ret*=n-1;
14     return ret;
15 } 
16 int main(void)
17 {
18     int t,n;
19     scanf("%d",&t);
20     while(t--)
21     {
22         scanf("%d",&n);
23         printf("%d\n",erlar(n));
24     }
25     return 0;
26 }

 

posted @ 2014-04-08 09:32  heaventouch  阅读(206)  评论(0编辑  收藏  举报