26 lines
412 B
C++
26 lines
412 B
C++
#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保证了在最后一步肯定会执行该if判断
|
|
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;
|
|
}
|
|
|
|
|