The meaning of the question is very clear, that is, finding the different logarithm that satisfies gcd (n-a, n) * gcd (n-B, n) = n ^ K (A, B. Obviously gcd (n-a, n) <= N, gcd (n-B, n) <= n. Therefore, when n is not 1 and K is> 2, the condition (a, B) does not exist ). When K = 2, only (n, n) meet the conditions. Therefore, only n = 1 and K = 1 need to be discussed separately:
When n = 1, No matter what value K is, there are only () conditions, and the result is 1;
When K is 1, that is, gcd (n-a, n) * gcd (n-B, n) = N, then gcd (n-a, n) = I, then gcd (n-B, n) = N/I. That is, to obtain the (, b) logarithm and.
1 #include <cstdio> 2 #include <cmath> 3 4 const int MOD = (1e9+7); 5 6 __int64 getNotDiv(int x) { 7 int i, r = x; 8 __int64 ret = x; 9 10 for (i=2; i*i<=r; ++i) {11 if (x%i == 0) {12 ret -= ret/i;13 while (x%i == 0)14 x /= i;15 }16 }17 if (x > 1)18 ret -= ret/x;19 return ret;20 }21 22 int main() {23 int n, k;24 int i, j;25 __int64 ans, tmp;26 27 while (scanf("%d %d", &n, &k) != EOF) {28 if (n==1 || k==2)29 printf("1\n");30 else if (k==1) {31 ans = 0;32 for (i=1; i*i<=n; ++i) {33 if (n%i == 0) {34 j = n/i;35 tmp = getNotDiv(i)*getNotDiv(j)%MOD;36 if (j == i) {37 ans += tmp;38 } else {39 ans += tmp<<1;40 }41 ans %= MOD;42 }43 }44 printf("%I64d\n", ans%MOD);45 } else {46 printf("0\n");47 }48 }49 50 return 0;51 }
[Hdoj] 4983 goffi and GCD