HDU 1286 Find a new friend: http://acm.hdu.edu.cn/showproblem.php?pid=1286
Question: Chinese problem.
Idea: The pure template problem of Euler function, there is nothing to say, it is mainly to understand the meaning of Euler function.
In number theory, for positive integers n, Euler functions are less than or equal to n number of numbers with n coprime. This function, named after its first researcher Euler, is also known as the Euler ' s totient function, φ functions, Euler quotient, and so on. For example φ (8) = 4, because 1,3,5,7 and 8 coprime. ----by degrees Niang.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
#include <stdio.h>
int eular (int n) {
int ret = 1;
for (int i = 2; i*i <= n;i++)
if (n%i = = 0) {
n/= i, ret *= i-1;
while (n%i = = 0)
n/= i, ret *= i;
}
if (n > 1)
ret *= n-1;
return ret;
}
int T, n;
int main ()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
printf ("%d\n", Eular (n));
}
return 0;
}
HDU 1286