山东省第八届acm大赛 G题 (SDUT 3899)

来源:互联网 发布:淘宝开店要2张银行卡 编辑:程序博客网 时间:2024/05/21 14:02



sum of power

Time Limit: 1000MS Memory Limit: 65536KB

Problem Description

Calculate  mod (1000000000+7) for given nm.

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





快速幂+大数求和    超过上限就取模降下来     




AC代码:

#include <stdio.h>const int d=1000000000+7;long long power(long long n,long long m){    n=n%d;//            取模    long long temp=1;    while (m){        if (m%2)            temp=(temp*n)%d;        m=m/2;        n=(n*n)%d;//           取模    }    return temp;}int main (){    long long n,m;    scanf ("%ld%ld",&n,&m);    long long sum=0;    for (int i=1;i<=n;i++){        sum=(sum+power(i,m))%d;//             取模    }    printf ("%lld\n",sum);    return 0;}



0 0
原创粉丝点击