Sample Input
3
4
5
18
36
360
2147483647
Sample Output
1
1
2
3
6
48
1073741823
Topic Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=3937
The main topic: There are n points on the circle to divide the circle into n equal, to find the same point can be a stroke of all points of the method;
Think: To be a stroke, then (N,K) must not intersect in the middle, but only in the starting position. (k as a k equal), so K is and N coprime number, and because K=1 and k=n-1, the result is the same, so the final result divided by 2;
Idea: To find the number of 1-n coprime. You can use the Φ function of the Euler function
Reprint please specify the Source: Search & Star Children
The value of the Φ function is general formula: φ (x) =x (1-1/P1) (1-1/P2) (1-1/P3) (1-1/P4) .... (1-1/PN), where P1, P2......pn is all factorization of x, and X is an integer that is not 0. φ (1) =1 (the number of unique and 1 coprime (less than or equal to 1) is 1 itself). (Note: Only one of each mass dependent.) Like 12=2*2*3. φ (12) =12* (1-1/2) * (1-1/3) =4
If n is the K-power of the prime number p, φ (n) =p^k-p^ (k-1) = (p-1) p^ (k-1), because except for multiples of p, the other numbers are followed by n coprime.
Set n as a positive integer, with φ (n) representing no more than N and an n mutual
The number of positive integers of the element, called the Euler function value of n, where the function
Φ:n→n,n→φ (N) is called Euler function.
Euler functions are integrable functions--if M,n coprime, φ (MN) =φ (m) φ (n).
Special properties: When n is odd, φ (2n) =φ (n) is shown to be similar to the above. Reprinted from: Euler function
#include <stdio.h>
#define LL Long long
//uva with
ll Fun (ll m)
{
ll res=m;
for (LL i=2;i*i<=m;i++)
{
if (m%i==0)
{
res= (res* (i-1))/I; printf ("i=%i64d,res=%i64d\n", i,res);
while (m%i==0)
{
m/=i;}}
}
if (m>1) res= (res* (m-1))/m;
return res;
}
int main ()
{
LL n;
while (scanf ("%lld", &n)!=eof)
{
printf ("%lld\n", Fun (n)/2);
}
return 0;
}
Or
#include <stdio.h>
#include <math.h>
int eular (int n)
{
int ret=1,i;
for (i=2; i<=sqrt (n); i++)
{
if (n%i==0)
{
n=n/i;
Ret*= (i-1);
while (n%i==0)
{
// printf ("n=%d\ti=%d\tret=%d\n", N,i,ret);
n/=i;
ret*=i;//such as Better
}}
}
if (n>1)
ret*= (n-1);
return ret;
}
int main ()
{
int t,a,j;
while (scanf ("%d", &a)!=eof)
{
printf ("%d\n", Eular (a)/2);
}
return 0;
}