#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
using namespace std;
void write1(int val) {
int level=0;
while(val!=0) {
bool bit=(val&1);
val>>=1;
if(val>0) {
if(bit) {
if(val==1) {
cout<<"1+(1+1)";
break;
} else cout<<"1+(1+1)*(";
} else {
if(val==1) {
cout<<"1+1";
break;
} else cout<<"(1+1)*(";
}
++level;
} else {
if(bit) cout<<"1";
}
}
for(int i=0;i<level;++i) cout<<')';
cout<<'\n';
}
int main(int argc, char** argv) {
int tests;
std::ios::sync_with_stdio(false); // przyspieszenie wejścia/wyjścia
cin>>tests;
for(int t=0;t<tests;++t) {
int val;
cin>>val;
write1(val);
}
return 0;
}
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 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<stdio.h> #include<stdlib.h> #include<iostream> #include<string> using namespace std; void write1(int val) { int level=0; while(val!=0) { bool bit=(val&1); val>>=1; if(val>0) { if(bit) { if(val==1) { cout<<"1+(1+1)"; break; } else cout<<"1+(1+1)*("; } else { if(val==1) { cout<<"1+1"; break; } else cout<<"(1+1)*("; } ++level; } else { if(bit) cout<<"1"; } } for(int i=0;i<level;++i) cout<<')'; cout<<'\n'; } int main(int argc, char** argv) { int tests; std::ios::sync_with_stdio(false); // przyspieszenie wejścia/wyjścia cin>>tests; for(int t=0;t<tests;++t) { int val; cin>>val; write1(val); } return 0; } |
English