syu问题 B: 找新朋友

版权声明:转载请注明出处 https://blog.csdn.net/qq_41431457/article/details/88368758

题目描述

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

输入

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

输出

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

样例输入

2
25608
24027

样例输出

7680
16016

暴力

#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int main()
{
	int test,n;
	cin>>test;
	while(test--)
	{
		int ans=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		if(gcd(i,n)>1) ans++;
		cout<<n-ans<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41431457/article/details/88368758