#include<bits/stdc++.h> using namespace std; void solve() { int n, on = 0; scanf("%d", &n); if(n==1) { printf("1\n"); return;} while(n!=1) { if(n%2==1){ printf("(1+");n--;on++;} else { if(n/2==1) printf("(1+1)"); else printf("(1+1)*"); n/=2;} } while(on--) printf(")"); printf("\n"); } int main() { int t; scanf("%d", &t); while(t--) solve(); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<bits/stdc++.h> using namespace std; void solve() { int n, on = 0; scanf("%d", &n); if(n==1) { printf("1\n"); return;} while(n!=1) { if(n%2==1){ printf("(1+");n--;on++;} else { if(n/2==1) printf("(1+1)"); else printf("(1+1)*"); n/=2;} } while(on--) printf(")"); printf("\n"); } int main() { int t; scanf("%d", &t); while(t--) solve(); } |