找新朋友(1286)

新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员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

//有点像筛选法

#include <stdio.h> 
#include <string.h>  
#include <math.h>  
#include <stdlib.h>  
#include <ctype.h>    
int maxgongyueshu(int m,int n)
{
    int a,b,temp;
    if (m >= n)
    {
          a = m;
          b = n;
    }
    else
    {
        a = n;
        b = m;
    }
    
    do 
    {
        temp = a % b;
        a = b;
        b = temp;
    }while (b);
    return a;
} 
int s[32768];  
int main()  
{  
    int i,j,n,t,count;  
    while(scanf("%d",&t)!=EOF)  
    {  
        while(t--)  
        {  
            scanf("%d",&n);  
            
            for(i=1;i<=n;i++)  
            s[i]=1;  
            
            for(i=2;i<=n;i++)  
            {  
                if(n%i==0)  
                for(j=i;j<=n;j+=i)  
                s[j]=0;  
            }  
            count=0;  
            
            if(n!=1)   
            for(i=1;i<=n;i++)  
            if(s[i])   
            count++;  
            
            printf("%d\n",count);        
        }  
    }  
    
    return 0;  
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值