Think:
PS : 题目出处“浪潮杯”山东省第八届ACM大学生程序设计竞赛
题目要求 就是 计算 从1到n的m次幂运算的和, 同时注意mod取余运算;
Problem Description
Calculate mod (1000000000+7) for given n,m.
Input
Input contains two integers n,m(1≤n≤1000,0≤m≤10).
Output
Output the answer in a single line.
Example Input
10 0
Example Output
10
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
long long int ans;
long long int sum;
long long int p(int a, int n)
{
ans = 1;
for (int i = 0;i < n;i ++)
{
ans = ans * a;
ans = ans % mod;
}
return ans;
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
sum = 0;
for (int i = 1;i <= n;i ++)
{
sum = sum + p(i, m);
sum = sum % mod;
}
printf("%lld\n", sum);
}