Files
python/C++课程/第十四课位运算训练精讲/快速幂_2.cpp

26 lines
412 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include<bits/stdc++.h>
using namespace std;
int quick(int a,int b)
{
int s = 1;
while (b > 0) {
if (b & 1) {//b=b>>1<><31>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>϶<EFBFBD><CFB6><EFBFBD>ִ<EFBFBD>и<EFBFBD>if<69>ж<EFBFBD>
s = s * a;
}
a = a * a;
cout<<"b="<<b<<endl;
cout<<"s="<<s<<endl;
cout<<endl;
b = b >> 1;
}
return s;
}
int main() {
printf("%d",quick(2,10));
return 0;
}