a + b
Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)Problem Description
Input
Output
Sample Input
2 3 1 1 2 3 3 10 1 2 3Sample Output
6 60074
/*************************************************************************
    > File Name: 1007.cpp
    > Author: Stomach_ache
    > Mail: sudaweitong@gmail.com
    > Created Time: 2014年08月11日 星期一 07时44分39秒
    > Propose: 
 ************************************************************************/
#include <cstdio>
/*Let‘s fight!!!*/
typedef long long LL;
const LL mod = (LL)1e10 + 7;
LL mul(LL a, LL b) {
      LL res = 0;
    while (b) {
          if (b&1) if ((res += a) >= mod) res -= mod;
        a <<= 1;
        if (a >= mod) a -= mod;
        b >>= 1;
    }
    return res;
}
LL mod_pow(LL a, LL b) {
      LL res = 1;
    while (b) {
          if (b&1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
int main(void) {
    int t;
    scanf("%d", &t);
    while (t--) {
        LL n, k, ans = 0, x;
        scanf("%lld %lld", &n, &k);
        k %= 9560995488LL;
        for (int i = 0; i < n; i++) {
            scanf("%lld", &x);
            ans += mod_pow((x%mod+mod)%mod, k);
            if (ans >= mod) ans -= mod; 
        }
        printf("%lld\n", ans);
    }
    return 0;
}
ACdream 1007 (快速幂),布布扣,bubuko.com
原文:http://www.cnblogs.com/Stomach-ache/p/3904074.html