Shandong Province 8th ACM College Students Programming Contest G question sum of power fast power board sub-question

Title:

k = 1 n ( i m ) m O d ( 1000000000 + 7 )
Given n, m, find the value of this expression

analyze:

1 m + 2 m + 3 m + 4 m + . . . . . . . . ( n 1 ) m + n m
Exponentiation operation, and also take the remainder of a large number, definitely fast power, board question

Code:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<stdio.h>
#define mod 1000000007
#define ll long long
using namespace std;

ll f(ll a,ll b)
{
    ll ans =1;
    a = a %mod;
    while(b)
    {
        if(b&1) ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}
int main()
{
    int n,m;
    cin >> n >> m;
    ll sum = 0;
    for(int i = 1; i <=n;i++)
    {
        sum = (sum+f(i,m))%mod;
    }
    cout << sum << endl;
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325420194&siteId=291194637