您的位置:首页 > 其它

HDU 1420 Prepared for New Acmer

2013-07-01 10:16 435 查看
蒙哥马利算法 0ms

#include<iostream>
using namespace std;
int main()
{
int m;
__int64 a,b,c;
cin>>m;
while(m--)
{

cin>>a>>b>>c;
a%=c;
__int64 t=1;
while(b)
{
if(b&1) t=t*a%c;
b=b>>1;
a=(a*a)%c;
}
cout<<t<<endl;
}
return 0;
}


暴力法 109ms

#include<iostream>
using namespace std;
int main()
{
int m,i;
__int64 a,b,c;
cin>>m;
while(m--)
{

cin>>a>>b>>c;
a%=c;
__int64 t=a;
for(i=2;i<=b;i++)
{
t=(t*a)%c;
if(t==0) break;
}
cout<<t<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: