a^b(位运算&快速幂)

题目链接

题目:

 

 

 题解:很简单、经典的的一道快速幂的题 注意一下用LL型就ok。

代码:

 1 #include <map>
 2 #include <set>
 3 #include <list>
 4 #include <stack>
 5 #include <queue>
 6 #include <deque>
 7 #include <cmath>
 8 #include <ctime>
 9 #include <string>
10 #include <limits>
11 #include <cstdio>
12 #include <vector>
13 #include <iomanip>
14 #include <cstdlib>
15 #include <cstring>
16 #include <istream>
17 #include <iostream>
18 #include <algorithm>
19 #define ci cin
20 #define co cout
21 #define el endl
22 #define Scc(c) scanf("%c",&c)
23 #define Scs(s) scanf("%s",s)
24 #define Sci(x) scanf("%d",&x)
25 #define Sci2(x, y) scanf("%d%d",&x,&y)
26 #define Sci3(x, y, z) scanf("%d%d%d",&x,&y,&z)
27 #define Scl(x) scanf("%I64d",&x)
28 #define Scl2(x, y) scanf("%I64d%I64d",&x,&y)
29 #define Scl3(x, y, z) scanf("%I64d%I64d%I64d",&x,&y,&z)
30 #define Pri(x) printf("%d\n",x)
31 #define Prl(x) printf("%I64d\n",x)
32 #define Prc(c) printf("%c\n",c)
33 #define Prs(s) printf("%s\n",s)
34 #define For(i,x,y) for(int i=x;i<y;i++)
35 #define For_(i,x,y) for(int i=x;i<=y;i++)
36 #define FFor(i,x,y) for(int i=x;i>y;i--)
37 #define FFor_(i,x,y) for(int i=x;i>=y;i--)
38 #define Mem(f, x) memset(f,x,sizeof(f))
39 #define LL long long
40 #define ULL unsigned long long
41 #define MAXSIZE 100005
42 #define INF 0x3f3f3f3f
43 
44 LL mod;
45 const double PI = acos(-1.0);
46 
47 using namespace std;
48 void power(LL a,LL b)
49 {
50     LL ans=1%mod;
51     while(b)
52     {
53         if(b&1)
54             ans=a*1ll*ans%mod;
55         a=a*1ll*a%mod;
56         b>>=1;
57     }
58     cout << ans;
59 }
60 int main()
61 {
62     int a,b;
63     cin>>a>>b>>mod;
64     power(a,b);
65     return 0;
66 }
View Code

 

posted @ 2020-06-25 11:14  hbhdhd  阅读(746)  评论(0编辑  收藏  举报