代码
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
//整数的进制转换
vector<char> numConvert(int num,int R){
vector<char> v;
while(num > 0){
char x = (char)(num % R + '0');
v.push_back(x);
num /= R;
}
reverse(v.begin(),v.end());
return v;
}
int getRes(int a,int coefficient){
int res = 1;
//二进制的指数
vector<char> v = numConvert(coefficient,2);
int len = v.size() - 1;
while(len >= 0){
res *= pow(a,2)*pow(a,(int)(v[len]-'0'));
len--;
}
return res;
}
int main(){
//霍纳法则
//括号最里面的x的系数是最高位系数
int res = getRes(2,10);
cout<<res;
return 0;
}