Acdream a + b

http://acdream.info/problem?pid=1007

两个 long long 相乘会超long long

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define maxn 10000
#define mod 10000000007
using namespace std; ll a[maxn];
ll n,k,t;
ll fMul(ll a, ll b) {
ll t = , y = a;
while(b) {
if(b & ) t = (t + y) % mod;
y = (y + y) % mod;
b >>= ;
}
return t;
} ll modExp(ll a, ll b) {
ll t = , y = a;
while(b) {
if(b & ) t = (fMul(t, y)) % mod;
y = (fMul(y, y)) % mod;
b >>= ;
}
return t;
} int main()
{
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&n,&k);
ll sum=;
for(int i=; i<n; i++)
{
scanf("%lld",&a[i]);
}
for(int i=; i<n; i++)
{
a[i]=((a[i]%mod)+mod)%mod;
ll c=modExp(a[i],k);
sum=(sum+c)%mod;
}
printf("%lld\n",sum);
}
return ;
}
上一篇:Oracle 支持在具有 DHCP 分配的 IP 地址的系统上进行安装


下一篇:内层DIV超出后,出现滚动条问题