题意:
求x^a,,,, 所有数导数之和,分子,分母的最大公约数。
题解:
sum=a1+a2+a3+......;
其实分母就是x^sum;
分子为 x^sum-a1+x^sum-a2.......;
求出分子的x最小次方就行了。
但是形如 2 2
29 29
2^29 +2^29 =2^30;
所以,当最小次方的个数是x倍数,想上进x倍数次。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#define LL long long
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
LL a[maxn];
LL calc(LL x,LL y){
LL ret=1;
while(y){
if(y%2==1){
ret=(ret%mod*x%mod)%mod;
}
y/=2;
x=(x%mod*x%mod)%mod;
}
return ret;
}
map<LL,LL>m;
map<LL,LL>::iterator it;
int main(){
int n,x;
LL sum=0;
scanf("%d %d",&n,&x);
for(int i=0;i<n;++i){
scanf("%lld",&a[i]);
sum+=a[i];
}
for(int i=0;i<n;++i) {
a[i]=sum-a[i];
m[a[i]]++;
}
LL num,cnt,ans=sum;
while(1){
it=m.begin();
num=it->first;
cnt=it->second;
m.erase(num);
if(cnt%x>0){
if(num<sum) ans=num;
break;
}
cnt/=x;
m[++num]+=cnt;
}
printf("%lld\n",calc(x,ans));
return 0;
}