#include <bits/stdc++.h>
using namespace std;
string licz(int n){
string pom;
if (n == 1)
return "1";
if (n > 0)
pom = licz(n / 2);
if (pom.size() == 1){
pom += "+1";
}
else{
if (pom[pom.size() - 1] == ')')
pom = pom + "*(1+1)";
else
pom = "(" + pom + ")*(1+1)";
}
if (n % 2 == 1)
pom += "+1";
return pom;
}
int main(){
int z;
scanf("%d", &z);
while(z--){
int n;
scanf("%d", &n);
string s = licz(n);
cout << s << 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 | #include <bits/stdc++.h> using namespace std; string licz(int n){ string pom; if (n == 1) return "1"; if (n > 0) pom = licz(n / 2); if (pom.size() == 1){ pom += "+1"; } else{ if (pom[pom.size() - 1] == ')') pom = pom + "*(1+1)"; else pom = "(" + pom + ")*(1+1)"; } if (n % 2 == 1) pom += "+1"; return pom; } int main(){ int z; scanf("%d", &z); while(z--){ int n; scanf("%d", &n); string s = licz(n); cout << s << endl; } } |
English