[2021-05-14]快速幂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
using namespace std;
int b,p;
long long ksm(int a,int b)
{
long long s=1;
while(b>0)
{
if(b%2==1)
{
s*=a;
}
b=b/2;
a*=a;
}
return s;
}
int main()
{
cin>>b>>p;
cout<<ksm(b,p);
return 0;
}