标签:uri image black 欧拉函数 one 来源 stat out 输出
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12134 Accepted Submission(s): 6430
2 25608 24027
7680 16016欧拉函数用于计算小于等于N,并与N互质的正整数。
12345678910111213141516171819202122232425262728293031323334353637#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAX 32769
using
namespace
std;
int
Eu(
int
n)
{
int
ret = n;
for
(
int
i = 2;i*i<=n;i++)
{
if
(n%i==0)
{
ret = ret/i*(i-1);
}
while
(n%i==0) n/=i;
}
if
(n>1) ret=ret*(n-1)/n;
return
ret;
}
int
main()
{
int
N;
cin>>N;
while
(N--)
{
int
n;
scanf
(
"%d"
,&n);
int
ans = Eu(n);
cout<<ans<<endl;
}
}
标签:uri image black 欧拉函数 one 来源 stat out 输出
原文地址:http://www.cnblogs.com/liwenchi/p/7259368.html