首页 > 代码库 > 快速幂取模

快速幂取模

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 #define LL long long
 6 
 7 int Max=100;
 8 LL fun(LL x,LL n)
 9 {
10     LL res=1;
11     while(n>0)
12     {
13         if(n&1)
14             res=(res*x)%Max;
15         x=(x*x)%Max;
16         n>>=1; 
17     }
18     return res;
19 }
20 int main()
21 {
22     LL x,n;
23     while(scanf("%lld %lld",&x,&n)!=EOF)
24     {
25         LL ans=fun(x,n);
26         printf("%lld\n",ans);
27     }
28     return 0;
29 }

 

快速幂取模