快速幂

来源:互联网 发布:java公司贷款培训骗局 编辑:程序博客网 时间:2024/04/16 14:31
int PowerMod(int a, int b, int c){   int ans = 1;a = a % c;     while (b>0){           if (b % 2 == 1)   ans = (ans * a) % c;             b = b / 2;         a = (a * a) % c;        }   return ans;}#include <cstdio>#include <cstring>typedef __int64 LL;const int mod = 12312311223;LL solve(int a,int n){    LL res = 1;    LL temp = a;    for(;n;n=n/2)    {        if(n%2==1)            res=(res*temp)%mod;        temp = (temp%mod)*(temp%mod)%mod;    }    return res;}int main(){    int a,n;    while(scanf("%d%d",&a,&n)!=EOF)    {        printf("%I64d\n",solve(a,n));    }    return 0;}

0 0
原创粉丝点击