HDU 6027 Easy Summation

xiaoxiao2021-02-28  88

http://acm.hdu.edu.cn/showproblem.php?pid=6027

这题因为k很小,自己手写一个函数算一个数的k次幂,然后直接跑就行了。

代码如下:

#include<bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; long long mypow(int x, int k) { long long ans = 1; while(k--) ans = (ans * x) % Mod; return ans; } int main() { int T, n, k; long long ans, tmp; cin >> T; while(T--) { cin >> n >> k; ans = 0; for(int i = 1; i <= n; i++) { tmp = mypow(i, k); ans = (ans + tmp) % Mod; } cout << ans << endl; } return 0; }

转载请注明原文地址: https://www.6miu.com/read-80792.html

最新回复(0)