#include <iostream>
#include <vector>
#include <cmath>
#ifndef WE_WANT_TO_BE_SANE_NOT_SANIC
#define ENDL "\n"
#else
#define ENDL std::endl
#endif
std::vector<int> primes {2, 3, 5, 7, 11};
std::string jedynkowanie(int x) {
#ifdef WE_WANT_TO_BE_SANE_NOT_SANIC
std::cerr << x << ENDL;
#endif
if (x < 4) {
std::string s = "(1";
for (int i = 1; i < x; i++) s += "+1";
return s+")";
} else {
if (x % 2 == 0) {
return "(1+1)*"+jedynkowanie(x/2);
}
if (x % 3 == 0) {
return "(1+1+1)*"+jedynkowanie(x/3);
}
return "(1+"+jedynkowanie(x-1)+")";
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int maxq = 0;
int n;
std::cin >> n;
int q[n];
for (int i = 0; i < n; i++) {
std::cin >> q[i];
if (q[i] > maxq) maxq = q[i];
}
if (maxq <= 100) {
for (int i = 0; i < n; i++) {
std::cout << 1;
for (int j = 1; j < q[i]; j++) std::cout << "+1";
std::cout << ENDL;
}
} else {
for (int i = 0; i < n; i++) {
if (q[i] <= 100) {
std::cout << '1';
for (int j = 1; j < q[i]; j++) std::cout << "+1";
std::cout << ENDL;
} else {
std::cout << jedynkowanie(q[i]) << ENDL;
}
}
}
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <iostream> #include <vector> #include <cmath> #ifndef WE_WANT_TO_BE_SANE_NOT_SANIC #define ENDL "\n" #else #define ENDL std::endl #endif std::vector<int> primes {2, 3, 5, 7, 11}; std::string jedynkowanie(int x) { #ifdef WE_WANT_TO_BE_SANE_NOT_SANIC std::cerr << x << ENDL; #endif if (x < 4) { std::string s = "(1"; for (int i = 1; i < x; i++) s += "+1"; return s+")"; } else { if (x % 2 == 0) { return "(1+1)*"+jedynkowanie(x/2); } if (x % 3 == 0) { return "(1+1+1)*"+jedynkowanie(x/3); } return "(1+"+jedynkowanie(x-1)+")"; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int maxq = 0; int n; std::cin >> n; int q[n]; for (int i = 0; i < n; i++) { std::cin >> q[i]; if (q[i] > maxq) maxq = q[i]; } if (maxq <= 100) { for (int i = 0; i < n; i++) { std::cout << 1; for (int j = 1; j < q[i]; j++) std::cout << "+1"; std::cout << ENDL; } } else { for (int i = 0; i < n; i++) { if (q[i] <= 100) { std::cout << '1'; for (int j = 1; j < q[i]; j++) std::cout << "+1"; std::cout << ENDL; } else { std::cout << jedynkowanie(q[i]) << ENDL; } } } return 0; } |
English