#include<stdio.h> #include<string> using namespace std; int main() { int zes; scanf("%d",&zes); while(zes--) { int n;scanf("%d",&n); if(n==1) {printf("1\n"); continue;} string s = (n%2==1) ? "1+(1+1)" : "(1+1)"; printf("%s",s.c_str()); n/=2; int close=0; while(n/2) { if(n%2==1) { printf("*(1+(1+1)"); close++; } else { printf("*(1+1)"); } n/=2; } s=string(close,')'); printf("%s\n",s.c_str()); } }
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<stdio.h> #include<string> using namespace std; int main() { int zes; scanf("%d",&zes); while(zes--) { int n;scanf("%d",&n); if(n==1) {printf("1\n"); continue;} string s = (n%2==1) ? "1+(1+1)" : "(1+1)"; printf("%s",s.c_str()); n/=2; int close=0; while(n/2) { if(n%2==1) { printf("*(1+(1+1)"); close++; } else { printf("*(1+1)"); } n/=2; } s=string(close,')'); printf("%s\n",s.c_str()); } } |