#include <iostream>
using namespace std;
void write(unsigned long long n, bool bracketed) {
bool hasOne = false;
if(n&1) {
cout << "1";
hasOne = true;
}
if (n > 1) {
if (hasOne) {
cout << "+(1+1)";
} else{
if(bracketed && n < 4) {
cout << "1+1";
} else {
cout << "(1+1)";
}
}
if(n>3) {
cout << "*";
cout << "(";
write(n/2, true);
cout << ")";
}
}
}
void doTc() {
unsigned long long n;
cin >> n;
write(n, false);
cout << endl;
}
int main () {
int tc;
cin >> tc;
for (int i = 0 ; i < tc ; i++) {
doTc();
}
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> using namespace std; void write(unsigned long long n, bool bracketed) { bool hasOne = false; if(n&1) { cout << "1"; hasOne = true; } if (n > 1) { if (hasOne) { cout << "+(1+1)"; } else{ if(bracketed && n < 4) { cout << "1+1"; } else { cout << "(1+1)"; } } if(n>3) { cout << "*"; cout << "("; write(n/2, true); cout << ")"; } } } void doTc() { unsigned long long n; cin >> n; write(n, false); cout << endl; } int main () { int tc; cin >> tc; for (int i = 0 ; i < tc ; i++) { doTc(); } return 0; } |
English