problem DescriptionGoffi is doing his math homework and he finds a equality on his text book:gcd(n−a,n)xgcd(n−b,n)=n k .
Goffi wants to know the number of (a,b ) satisfy the equality, ifNandkis given and1≤a,b≤n .
Note:< Span id= "mathjax-span-45" class= "Mrow" >gcd (a , b) means Greatest common divisor of a and b .
InputInput contains multiple test cases (less than 100). For each test case, there's one line containing the integersNand k (1≤n,k≤9 ).
OutputFor each test case, output a single integer indicating the number of a,b) modulo 9+7.
Sample Input
2 1
3 2
Sample Output
2 1
Hint
for the first case, (2, 1) and (1, 2) satisfy the equality.
Sourcebestcoder Round #6
Find yourself Euler function All to forget, all hurriedly fill the question ...
1, k!=1 the situation is very simple, remember to put if (k==2 | | n==1) This special sentence in the IF (k>2) in front, because this WA for a long time, various reasons for their own thinking.
2, the following discussion k=1 situation. X=GCD (n-a,n), then N/X=GCD (n-b,n), because N-a can take 0...n-1 is 1....N, so can completely remove the N-limit, that is, gcd (a,n) =x, gcd (b,n) =n/x when the number, because A<=n, So the number of gcd (a,n) =u[n/x],u is the Euler function. So the original is equal to Sigma (U[n/x]*u[x]) where x is the approximate sum of N.
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 #defineMOD 10000000076 #definell Long Long7 ll Eular (ll N)8 {9ll res=1;Ten for(LL i=2; i*i<=n;i++) One { A if(n%i==0) - { -n/=i,res*=i-1; the while(n%i==0) - { -N/=i; -res*=i; + } - } + } A if(n>1) res*=n-1; at returnRes; - } - ll N,k; - intMain () - { - while(SCANF ("%i64d%i64d", &n,&k) = =2) in { - if(k==2|| n==1) to { +printf"1\n"); - Continue; the } * if(k>2) $ {Panax Notoginsengprintf"0\n"); - Continue; the } + All ans=0; the for(LL i=1; i*i<=n;i++) + { - if(n%i==0) $ { $ if(i*i!=N) -Ans= (Ans+eular (n/i) *eular (i) *2)%MOD; - Else theAns= (Ans+eular (n/i) *eular (i))%MOD; - }Wuyi } theprintf"%i64d\n", ans); - Wu } - return 0; About}
View Code
Hdu 4983 Goffi and GCD (Euler function)