快速幂模板

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 int f(int x,int n)
 6 {
 7     int now=1;
 8     while(n)
 9     {
10         if(n&1)
11         {
12             now=now*x;
13         }
14         x=x*x;
15         n>>=1;
16     }
17     return now;
18 }
19 int main()
20 {
21     int x,n;
22     cin>>x>>n;
23     cout<<f(x,n);
24     return 0;
25 }
原文地址:https://www.cnblogs.com/zwfymqz/p/6675322.html