[Hdoj] 4983 goffi and GCD

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.