GCD Again
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2611 Accepted Submission (s): 1090
problem DescriptionDoes spent some time to think and try to solve those unsolved problem after one ACM contest?
No?
Oh, you must does this if you want to become a "Big cattle".
Now you'll find the This problem are so familiar:
The greatest common divisor GCD (A, b) of both positive integers a and B, sometimes written (a, b), is the largest divisor Common to A and B. For example, (1, 2) = 1, (12, 18) =6. (A, B) can is easily found by the Euclidean algorithm. Now I am considering a little more difficult problem:
Given An integer N, please count the number of the integers M (0<m<n) which satisfies (n,m) >1.
This was a simple version of the problem "GCD" which you had done with a contest RECENTLY,SO I name This problem "GCD Again". If you cannot solve it still,please take a good think about your method of study.
Good luck!
InputInput contains multiple test cases. Each test case is contains an integers N (1<n<100000000). A test case containing 0 terminates, the input and this test are not processed.
Outputfor each integers N should output the number of integers M on one line, and with one line of output for each line In input.
Sample Input
240
Sample Output
01
Knowledge Reserve:
I. Concept of coprime:
1. Definition
Coprime ( relatively primeì) is also called the mutual vegetarian. If the maximum common factor of n integers is 1, it is called the n integer coprime.
For example 8, the maximum common factor of 10 is 2, not 1, so it is not an integer coprime.
The maximum common factor of 7,10,13 is 1, so this is an integer coprime.
5 and 5 are not coprime, since the common factor of 5 and 5 is 1, 5.
1 and no matter what number are multiplied, but and no matter what number are coprime. Since the 1 factor is only 1, the Inma principle is that only two of the male factor is only 1 o'clock. Say two number is Inma. 1 has only one factor (so 1 is neither prime (prime number) nor composite), and no other common factor of 1 and other numbers can be found. so 1 and no matter what number are coprime (except 0).
Inma: such as C and M coprime, then writing (c,m) = 1.
The math textbook for primary schools defines Inma as: "The number of conventions is only two of 1." Called Inma. ”
The "two numbers" mentioned here refers to the natural numbers.
"The number of conventions is only 1" and cannot be erroneously stated as "without the number of conventions."
”
Two. Euler functions:
1. Definition:
for a positive integer n, the Euler function is less than or equal to the number of n coprime in the number of numbers. For example, Euler (8) = 4, due to 1,3,5,7 and 8 coprime.
2. Description:
Euler function Expression formula: Euler (x) =x (1-1/P1) (1-1/P2) (1-1/P3) (1-1/P4) ... (1-1/PN), in which P1,P2......PN is the total factor of X. X is an integer that is not 0.
(Note: Each quality factor is only one.) For example 12 = 2*2*3 then φ (12) = 12 * (1-1/2) * (1-1/3) =4)
Euler (1) =1 (the number of unique and 1 coprime (less than equals) is 1 itself).
Euler function Properties: 1, φ (MN) =φ (m) φ (n)
2, if n is an odd number. φ (2n) =φ (n).
the extension of Euler's formula: the sum of all the mass factors of a number is Euler (n) *n/2.
Note: In Euler functions, the function value is [1, n] and the number of n Inma
Test Instructions:the number of gcd (i,n) less than n is greater than 1idea: Euler function directly seek gcd (I,n) ==1 number with n minus can, attention is less than n, so minus 1. detailed code such as the following:
#include <stdio.h>int Euler (int n)//Euler function {int res=n,i;for (i=2;i*i<=n;i++) {if (n%i==0) res=res/i* (i-1); /First Division is to prevent overflow of intermediate data while (n%i==0) n/=i;//guaranteed n must be prime}if (n>1) res=res/n* (n-1); return res;} int main () {int n;while (scanf ("%d", &n) &&n!=0) printf ("%d\n", N-euler (N)-1);//The topic requires less than n, so subtract 1 return 0 ;}
Hdoj 1787 GCD Again (Euler function)