题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6063
思路:列出几组数据可以发现规律,其实就和n的k次方一样,所以直接快速幂。
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define ll long long
#define ma(a) memset(a,0,sizeof(a))
const int MOD=1e9+7;
ll poww(ll m,ll n)
{
ll ans=1;
while(n)
{
if(n&1)ans=(ans*m)%MOD;
m=(m*m)%MOD;
n>>=1;
}
return ans;
}
int main()
{
ll m,n;
int k=1;
while(scanf("%lld %lld",&m,&n)!=EOF)
{
m%=MOD;
printf("Case #%d: %lld\n",k++,poww(m,n));
}
return 0;
}

123

被折叠的 条评论
为什么被折叠?



