#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
int Ncases;
cin >> Ncases;
for(int a = 0; a < Ncases; a++){
int cur;
cin >> cur;
int cp = cur;
int maxpow = 0;
while(cp != 1){
cp /= 2;
maxpow ++;
}
for(int i = 0 ; i < maxpow; i ++){
cout << "(";
}
cout << "1";
for(int i = 0 ; i < maxpow; i ++){
cout << "*(1+1)";
if((1 << maxpow - i - 1) & cur){
cout << "+1";
}
cout << ")";
}
cout << endl;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <iostream> #include <string> #include <map> using namespace std; int main(){ int Ncases; cin >> Ncases; for(int a = 0; a < Ncases; a++){ int cur; cin >> cur; int cp = cur; int maxpow = 0; while(cp != 1){ cp /= 2; maxpow ++; } for(int i = 0 ; i < maxpow; i ++){ cout << "("; } cout << "1"; for(int i = 0 ; i < maxpow; i ++){ cout << "*(1+1)"; if((1 << maxpow - i - 1) & cur){ cout << "+1"; } cout << ")"; } cout << endl; } } |
English