#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define mp make_pair
#define REP(i,n) for (int i=0,___=(n); i<___; ++i)
#define FOR(i,a,b) for (int i=(a),___=(b); i<=___; ++i)
#define FORD(i,a,b) for (int i=(a),___=(b); i>=___; --i)
int read() { int n; scanf("%d", &n); return n; }
ll readl() { ll n; scanf("%lld", &n); return n; }
char readc() { static char s[32]; scanf("%s", s); return *s; }
void jeden(int n) {
if (n < 4) {
if (n == 1) printf("1");
if (n == 2) printf("1+1");
if (n == 3) printf("1+1+1");
return;
}
if (n % 2 == 1) {
printf("1+(1+1)*(");
jeden(n / 2);
printf(")");
} else {
printf("(1+1)*(");
jeden(n / 2);
printf(")");
}
}
int main() {
int t = read();
while (t--) {
int n = read();
jeden(n);
printf("\n");
}
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 50 51 52 | #include <cstdio> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <sstream> #include <cmath> using namespace std; typedef vector<int> vi; typedef long long ll; typedef vector<ll> vll; typedef pair<int,int> pii; #define mp make_pair #define REP(i,n) for (int i=0,___=(n); i<___; ++i) #define FOR(i,a,b) for (int i=(a),___=(b); i<=___; ++i) #define FORD(i,a,b) for (int i=(a),___=(b); i>=___; --i) int read() { int n; scanf("%d", &n); return n; } ll readl() { ll n; scanf("%lld", &n); return n; } char readc() { static char s[32]; scanf("%s", s); return *s; } void jeden(int n) { if (n < 4) { if (n == 1) printf("1"); if (n == 2) printf("1+1"); if (n == 3) printf("1+1+1"); return; } if (n % 2 == 1) { printf("1+(1+1)*("); jeden(n / 2); printf(")"); } else { printf("(1+1)*("); jeden(n / 2); printf(")"); } } int main() { int t = read(); while (t--) { int n = read(); jeden(n); printf("\n"); } return 0; } |
English