</pre>新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。 Input第一行是测试数据的组数CN(Case number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。 Output对于每一个N,输出一行新朋友的人数,这样共有CN行输出。Sample Input22560824027Sample Output768016016<p></p><pre name="code" class="cpp">
<pre name="code" class="cpp">#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int eular(int x)
{
int res=x;
for(int i=2;i<floor(sqrt(x*1.0));i++)
{
if(x%i==0)
{
res-=res/i;
while(x%i==0)
{
x/=i;
}
}
}
if(x>1) res-=res/x;
return res;
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%d\n",eular(n));
}
return 0;
}
找新朋友 【欧拉函数】
最新推荐文章于 2025-06-14 15:57:24 发布