zjut 整数模

题目:http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1219


<span style="font-size:18px;">#include<stdio.h>
#include<iostream>
using namespace std;
typedef  __int64 LL;

LL mo(LL a,LL p,LL m){
    if(p==1) return a%m;
    if(p%2==1) return mo(a%m,p-1,m)*a%m;//这里mo*(a%m,p-1,m) 要加上%m
    return mo( (a*a)%m,p/2,m)%m;
}
int main(){
    unsigned a,p,m;
    LL ans;
    while(cin >> a >> p >> m){
        if(a==0&&p==0&&m==0) break;
        ans=mo(a,p,m);
        printf("%I64d\n",ans);
    }
    return 0;
}</span>


你可能感兴趣的:(zjut 整数模)