求a的b次方对c取余的值
3 2 3 5 3 100 10 11 12345 12345
3 1 10481
参考:http://acm.nyist.net/JudgeOnline/talking.php?pid=102 56楼
我不懂为什么这么做,记着~
#include<iostream>
#include<stdio.h>
using namespace std;
int dy(int m,int n,int p)
{
if(n==0)
return 1%p;
int temp=dy(m,n>>1,p);
temp=(long long)temp*temp%p;
if(n&1)
temp=(long long)temp*m%p;
return temp;
}
int main()
{
int T,m,n,p;
cin>>T;
while(T--)
{
cin>>m>>n>>p;
cout<<dy(m,n,p)<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/zuguodexiaoguoabc/article/details/46763463