#include <iostream>
#include <string>
using namespace std;
int n;
int res[2];
void znajdzPotege(int n){ //ustawia tablice dwuelementowa. res[0] to wartosc res[1] potega
res[0] = 1;
int i = 0;
while(res[0] <= n){
res[0] = res[0] << 1;
++i;
}
if(res[0] > n){
res[0] = res[0] >> 1;
i--;
}
res[1] = i;
}
int main(){
ios_base::sync_with_stdio(false);
int z;
cin >> z;
while(z--){
cin >> n;
znajdzPotege(n);
int najblizszaPotega_2 = res[1];
int dodatkoweJedynki = n - res[0];
if(najblizszaPotega_2 * 2 + dodatkoweJedynki > 100){
cout<<"NIE"<<endl;
}
string res ="";
while(najblizszaPotega_2--){
res+=("(1+1)*");
}
res.pop_back();
while(dodatkoweJedynki--){
res+= "+1";
}
cout<<res<<endl;
}
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 | #include <iostream> #include <string> using namespace std; int n; int res[2]; void znajdzPotege(int n){ //ustawia tablice dwuelementowa. res[0] to wartosc res[1] potega res[0] = 1; int i = 0; while(res[0] <= n){ res[0] = res[0] << 1; ++i; } if(res[0] > n){ res[0] = res[0] >> 1; i--; } res[1] = i; } int main(){ ios_base::sync_with_stdio(false); int z; cin >> z; while(z--){ cin >> n; znajdzPotege(n); int najblizszaPotega_2 = res[1]; int dodatkoweJedynki = n - res[0]; if(najblizszaPotega_2 * 2 + dodatkoweJedynki > 100){ cout<<"NIE"<<endl; } string res =""; while(najblizszaPotega_2--){ res+=("(1+1)*"); } res.pop_back(); while(dodatkoweJedynki--){ res+= "+1"; } cout<<res<<endl; } return 0; } |
English