http://codevs.cn/problem/3500/
http://www.acmicpc.sdnu.edu.cn/problem/show/1056
快速幂取余,原来看代码以为特别难,但没想到,原来这么简单啊。
详情看以下文章:http://blog.youkuaiyun.com/xuruoxin/article/details/8578992
PS:第二个链接的数据很弱int 就可以过,第一个很强,longlong 也不过 有一个是9亿多,我也没继续做。
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
long long a, b, k;
long long daan = 1;
cin >> a >> b >> k;
a = a%k;
while (b > 0)
{
if (b%2==1)
{
daan = (daan*a) % k;
}
b = b / 2;
a = a*a%k;
}
cout << daan << endl;
system("pause");
return 0;
}