D - a + b
Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu
Submit
Status
Practice
ACdream 1007
Description
Input
Output
Sample Input
2 3 1 1 2 3 3 10 1 2 3
Sample Output
6 60074
对一个数可以拆分为N=(P*(N/P)+(N%P))
负数取模为正数
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define MOD 10000000007
#define TEMP 1000000
using namespace std;
long long pow(long long a,long long b){if(b==0)return 1%MOD;long long t=pow(a%MOD,b>>1);long long n=t%MOD,m=a%MOD;n=t=(((n*TEMP%MOD)*((n/TEMP)%MOD))%MOD+n*(n%TEMP)%MOD)%MOD;if(b&1){t=(((n*TEMP%MOD)*((m/TEMP)%MOD))%MOD+n*(m%TEMP)%MOD)%MOD;}return t;
}
int main()
{long long sum,n,a,b,k,t;scanf("%lld",&t);while(t--){scanf("%lld%lld",&n,&k);sum=0;if(n<=0)break;for(int i=0;i<n;++i){scanf("%lld",&a);sum=sum+pow(a%MOD,k); sum=sum%MOD;}printf("%lld\n",(sum+MOD)%MOD);}return 0;
}