GCD of S and T to a prime number

Source: Internet
Author: User
Tags gcd

Topic Link: Http://codeforces.com/contest/359/problem/C

Meaning

Give a prime number X, and A1, a2......an, when you compute this equation, it becomes this form, and T equals Xa1+a2+...+an, and the gcd of S and T

(1≤n≤105, 2≤x≤109), result of 1000000007 modulo

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Analysis:

The direct analysis of s and T, can not think of how to seek gcd, then we can think about, GCD and what is related to: numerator and denominator divided by GCD can get the simplest fraction, we can start from here

Given the order of a in the topic, think about the usual way we calculate such fractions: first the denominator can be xan, and the numerator is the form of x ^ (AN-A1), x ^ (AN-A2).

At this time to consider whether can Tong, need to understand this problem first: Sigma (x ^ k) + 1 (k >= 1) is not divisible by x, because a addends can be divided by X, 1 obviously not, so the whole is not. Then, when considering the Tong, if the last 1 of the number can not reach the integer times X, the whole is not Tong, the key is to deal with here.

In addition to the question I did not think of: for (x * x)/x Such an expression, GCD is x but not X * x. Extra attention is needed when calculating Tong

const int MOD = 1000000007;     
         
const int MAXN = 110000;     
         
LL IPT[MAXN];     
    ll Qkpow (ll A, ll b) {ll ret = 1;     
        while (b) {if (b & 1) ret = ret * a% MOD;     
        b >>= 1;     
    A = A * a% MOD;     
return ret;     
    int main () {//Freopen ("In.txt", "R", stdin);     
    LL N, x;     
        while (CIN >> n >> x) {map<ll, ll> MP;     
         
        Map<ll, ll>::iterator it;     
        LL sum = 0;     
            FE (i, 1, n) {cin >> ipt[i];     
        Sum + + ipt[i];     
        FE (i, 1, n) {mp[ipt[n]-ipt[i]]++;     
            while (true) {it = Mp.begin ();     
            LL a = It->first, B = it->second;     
   if (b% x = = 0)         {while (b% x = = 0) {b/= x;     
                a++;     
                } mp.erase (it);     
            Mp[a] + b;     
        else break;     
    cout << Qkpow (x, Sum-ipt[n] + min (ipt[n), Mp.begin ()->first)) << Endl;     
return 0; }

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.