This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<iostream>
#include <bitset>
using namespace std;
//输出二进制
void printEr(int b) {
cout<<bitset<sizeof(b)*2>(b)<<endl;
}
//快速幂
int poww(int a, int b) {
int ans = 1, base = a;
while (b >0) {
//输出二进制的b
printEr(b);
//快速幂的核心算法
if (b & 1) //例如一个数 & 1 的结果就是取二进制的最末位。最后一位如果是1,表示是奇数,需要单独乘一次
ans *= base;
base *= base;
//右移一位,可以理解为除以2
b >>= 1;
return ans;
int main() {
cout << poww(2,5);
return 0;