链接http://vjudge.net/problem/ACdream-1007
参考http://blog.csdn.net/ac_gibson/article/details/47660529
为什么a为负,转成正数就能过,不转就超时了啊.
#include<stdio.h>
#include<iostream>
#define ll long long
using namespace std;
const ll m =10000000007;
ll a;
ll multi(ll a,ll b) //最开始没写这个,一直WR
{
ll ans=0;
while(b)
{
if(b&1) ans=(ans+a)%m;
b>>=1;
a=(a<<1)%m;
}
ans%=m;
return ans;
}
ll qpow(ll a,ll k){
if(!k) return 1;
ll r=1;
for(;k;k>>=1){
if(k&1)
r=multi(r,a)%m;
a=multi(a,a)%m;
}
return r;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
ll n,k;
scanf("%lld%lld",&n,&k);
ll ans=0;
for(ll i=0;i<n;i++){
scanf("%lld",&a);
ans=(ans+qpow(a,k))%m;
if(k&1){
if(a>=0)
ans=(ans+qpow(a,k))%m;
else
{
a*=-1;
ans=(ans-qpow(a,k))%m;
}
}
else
{
if(a<0)
a*=-1;
ans=(ans+qpow(a,k))%m;
}
}
printf("%lld\n",(ans+m)%m);
}
return 0;
}