Hdu2588 GCD (Euler's function)
Solve the number of I with less than n and with gcd (I, n) greater than m
Analysis:
For all the largest convention values less than n, it must be a factor of n. Therefore, start from this aspect and find the factor I is n. When I> m, solve the prime number multiple of car I and accumulate the number less than n. We thought that the maximum value of this number is n/I, so we can accumulate the Euler's function value of n/I.
The Code is as follows:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; long euler (long n) {// returns euler (n) long res = n, a = n; for (long I = 2; I * I <= a; I ++) {if (a % I = 0) {res = res/I * (I-1 ); // division is performed first to prevent intermediate data overflow while (a % I = 0) a/= I ;}} if (a> 1) res = res/a * (A-1); return res;} // Euler's function value long a [1000010]; int main () {long n, m; int t; cin> t; while (t --) {long ans = 0; scanf ("% I64d % I64d", & n, & m); for (int I = 1; I * I <= n; I ++) {// determine sqrt (n). if (n % I! = 0) continue; if (I> = m & I * I! = N) {ans + = euler (n/I);} if (n/I> = m) {ans + = euler (I); // one is I, one is n/I
} } printf("%I64d\n",ans); } return 0;}