#include<bits/stdc++.h> using namespace std; char twy[1009]; int naw; void wyp(int n) { if (n / 2 == 1) strcpy (twy, "(1+1)"); else { wyp (n / 2); strcat (twy, "*(1+1))"); ++naw; } if (n % 2 == 1) { strcat (twy, "+1)"); ++naw; } } int main() { int n,t; scanf("%d", &t); for (int abc = 0; abc < t; ++abc) { naw = 0; scanf ("%d", &n); if (n == 1) printf("1\n"); else { wyp (n); for (int i = 0; i < naw; ++i) printf("("); printf("%s\n",twy); } } 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 | #include<bits/stdc++.h> using namespace std; char twy[1009]; int naw; void wyp(int n) { if (n / 2 == 1) strcpy (twy, "(1+1)"); else { wyp (n / 2); strcat (twy, "*(1+1))"); ++naw; } if (n % 2 == 1) { strcat (twy, "+1)"); ++naw; } } int main() { int n,t; scanf("%d", &t); for (int abc = 0; abc < t; ++abc) { naw = 0; scanf ("%d", &n); if (n == 1) printf("1\n"); else { wyp (n); for (int i = 0; i < naw; ++i) printf("("); printf("%s\n",twy); } } return 0; } |