其他分享
首页 > 其他分享> > CF1361B

CF1361B

作者:互联网

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
const long long mod2 = 1e8+7;
const long long N  =1e6+10;
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)o(x/10);
    putchar(x%10+'0');
}
long long fastpower(long long x,long long k,long long mod){
    long long res=1;
    while(k>0){
        if(k&1)res*=x;
        res%=mod;
        x*=x;x%=mod;
        k>>=1;
    }
    return res;
}
long long t, n, p;
long long a[N];
signed main(){
    in(t);
    while(t--){
        in(n);in(p);

        for(long long i=1;i<=n;i++)in(a[i]);
        sort(a+1,a+n+1);

        long long ans1=0,ans2=0;
        for(long long i=n;i>=1;i--){
            if(ans1 == 0 && ans2 == 0){
                ans1+=fastpower(p,a[i],mod);
                ans2+=fastpower(p,a[i],mod2);
            }else{
                ans1-=fastpower(p,a[i],mod);ans1+=mod;ans1%=mod;
                ans2-=fastpower(p,a[i],mod2);ans2+=mod2;ans2%=mod2;
            }
        }

        o(ans1);putchar('\n');
    }
    return 0;
}

标签:mod2,ans1,ans2,CF1361B,long,fastpower,mod
来源: https://www.cnblogs.com/yesuweiYYYY/p/14279310.html