首页 > 代码库 > ACdream 1007 (快速幂)
ACdream 1007 (快速幂)
题目链接
a + b
Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)Problem Description
Input
Output
Sample Input
23 11 2 33 101 2 3
Sample Output
660074
/************************************************************************* > 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;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。