#include <cstdio> int main() { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); int count = 0; int liczba = 0; while (N != 0) { if (N%2 == 0) { count++; } else { if (count == 0) { printf("%d", 1); if (N > 1) printf("+"); else printf("\n"); } else { for (int i = 0; i < count; i++) { printf("(1+1)"); if (i != count-1) printf("*"); } if (N > 1) { liczba++; printf("*(1+"); } else { for (int i = 0; i < liczba;i++) printf(")"); printf("\n"); } } count = 1; } N /= 2; } } }
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 | #include <cstdio> int main() { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); int count = 0; int liczba = 0; while (N != 0) { if (N%2 == 0) { count++; } else { if (count == 0) { printf("%d", 1); if (N > 1) printf("+"); else printf("\n"); } else { for (int i = 0; i < count; i++) { printf("(1+1)"); if (i != count-1) printf("*"); } if (N > 1) { liczba++; printf("*(1+"); } else { for (int i = 0; i < liczba;i++) printf(")"); printf("\n"); } } count = 1; } N /= 2; } } } |