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; }