#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define MAX 100007
#define REP(x,n) for (int x = 0; x < (n); x++)
#define FOR(x,b,e) for (int x = (b); x <= (e); x++)
#define LL long long
#define ULL unsigned long long
#define MP std::make_pair
#define ST first
#define ND second
int main(){
int t,n;
int brackets;
scanf("%d", &t);
REP(x, t){
scanf("%d", &n);
brackets = 0;
if (n==1)
printf("1\n");
while (n > 1){
if (n % 2 == 1){
printf("(1");
brackets++;
n-=1;
if (n>0)
printf("+");
}
printf("(1+1)");
n/=2;
if(n > 1)
printf("*");
}
cout<<string(brackets, ')')<<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 34 35 36 37 38 39 40 41 42 | #include <cstdio> #include <iostream> #include <set> #include <vector> using namespace std; #define MAX 100007 #define REP(x,n) for (int x = 0; x < (n); x++) #define FOR(x,b,e) for (int x = (b); x <= (e); x++) #define LL long long #define ULL unsigned long long #define MP std::make_pair #define ST first #define ND second int main(){ int t,n; int brackets; scanf("%d", &t); REP(x, t){ scanf("%d", &n); brackets = 0; if (n==1) printf("1\n"); while (n > 1){ if (n % 2 == 1){ printf("(1"); brackets++; n-=1; if (n>0) printf("+"); } printf("(1+1)"); n/=2; if(n > 1) printf("*"); } cout<<string(brackets, ')')<<endl; } } |
English