快速幂模板

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 #include <queue>
13 using namespace std;
14 #define lowbit(x) (x&(-x))
15 #define max(x,y) (x>y?x:y)
16 #define min(x,y) (x<y?x:y)
17 #define MAX 100000000000000000
18 #define MOD 1000000007
19 #define pi acos(-1.0)
20 #define ei exp(1)
21 #define PI 3.141592653589793238462
22 #define INF 0x3f3f3f3f3f
23 #define mem(a) (memset(a,0,sizeof(a)))
24 typedef long long ll;
25 ll gcd(ll a,ll b){
26     return b?gcd(b,a%b):a;
27 }
28 bool cmp(int x,int y)
29 {
30     return x>y;
31 }
32 const int N=100005;
33 const int mod=1e9+7;
34 ll qpow(int x,int n)
35 {
36     ll ans=1;
37     while(n){
38         if(n&1)  // n & 1 等价于 (n % 2) == 1
39             ans*=x;
40         x*=x;
41         n>>=1;// n >>= 1 等价于 n /= 2
42     }
43     return ans;
44 }
45 int main()
46 {
47     std::ios::sync_with_stdio(false);
48     ll a,n;
49     while(cin>>a>>n){
50         cout<<qpow(a,n)<<endl;
51     }
52     return 0;
53 }
posted @ 2017-08-07 17:20  wydxry  阅读(410)  评论(0编辑  收藏  举报
Live2D