cf 359C

时间:2023-12-31 19:15:26

stl 里的map使用   然后就是快速幂取余

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <map>
#define LL long long
#define mod 1000000007
using namespace std;
LL num[100010];
LL pow_mod(LL a, LL n)
{
if(n == 0)
return 1;
LL x = pow_mod(a, n/2);
LL ans = (LL)x*x%mod;
if(n%2) ans = ans*a%mod;
return ans;
}
int main()
{
LL n, x, _max, sum = 0;
scanf("%I64d%I64d",&n,&x);
for(int i = 0; i < n; i++)
{
scanf("%I64d",&num[i]);
sum += num[i];
}
_max = sum;
for(int i = 0; i < n; i++)
{
num[i] = sum-num[i];
_max = min(_max, num[i]);
}
map<LL, int> g;
for(int i = 0; i < n; i++)
{
num[i] -= _max;
g[num[i]]++;
}
int r = 0;
for (int i = 0; ; i++)
{
r += g[i];
if (r % x || r == 0)
break;
r /= x;
_max++;
}
if(_max > sum)
_max = sum;
printf("%I64d\n",pow_mod(x%mod, _max));
return 0;
}