ACdream 1007

时间:2022-02-18 08:24:10

input

T           <=10

n k            n<=1000         k<=10^18

a1,a2,...an                |ai|<=10^18

output

(a1^k+a2^k+...+an^k)%10^10+7

Sample Input

2

3 1
1 2 3
3 10
1 2 3

Sample Output

6 60074

做法:快速幂+__int128,需注意ai可能是负数,模的是10^10+9,超int了

模乘法:对一个数可以拆分为N=(P*(N/P)+(N%P))

 #include <bits/stdc++.h>
#define MAX 100000
#define LL long long
//#define __int128 long long
#define mod 10000000007LL
using namespace std;
int cas=,T;
template <class T>
bool scanff(T &ret)
{ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&c!='.'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret=ret*+(c-'');
if(c==' '||c=='\n'){ ret*=sgn; return ; }
while(c=getchar(),c>=''&&c<='') ret+=(c-'')*bit,bit/=;
ret*=sgn;
return ;
}
template <class T>
void printff(T ret)
{ //Faster Output
char s[];
if(ret<) { printf("-");ret=-ret; }
int len=;
while(ret)
{
s[++len]=ret%+'';
ret/=;
}
if(!len) s[++len]='';
while(len)
{
printf("%c",s[len]);
len--;
}
}
LL qmod( __int128 a, LL n)
{
__int128 res=;
LL flag=;
if(a<) { flag=(n&?-:);a=-a; }
a%=mod;
while(n)
{
if(n&) res=res*a%mod;
a=a*a%mod;
n>>=;
}
return (LL)res*flag;
}
int main()
{
//freopen("1.in","w",stdout);
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%d",&T);
while(T--)
{
int n;
LL k,a,res=;
scanf("%d%lld",&n,&k);
for(int i=;i<n;i++)
{
scanf("%lld",&a);
res=(res+qmod(a,k))%mod;
}
printff((res+mod)%mod);
printf("\n");
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}