#include <vector> #include <map> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <string> using namespace std; #define LOG_ENABLED true #define INTERACTIVE false typedef long long ll; typedef unsigned long long ull; #define LOG if (LOG_ENABLED) cerr const ull INF = 1000000009ull; const int MAX_LENGTH = 100; string solveForSmall(int value) { string result = "1"; for (int i = 1; i < value; i++) { result += "+1"; } return result; } string solve(int value) { string result; if (value <= 5) { result = solveForSmall(value); } else { if (value % 2 == 0) { result = "(1+1)*(" + solve(value / 2) + ")"; } else { result = "1+" + solve(value - 1); } } return result; } void test() { int i, n; for (i = 1; i < 100; i++) { n = 1000000000 - i; // cout << "[" << n << "]: " << solve(n) << endl; cout << solve(n) << endl; } } void run() { int t, i, value; cin >> t; for (i = 0; i < t; i++) { cin >> value; cout << solve(value) << endl; } } int main() { if (true) { run(); } else { test(); } 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <vector> #include <map> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <string> using namespace std; #define LOG_ENABLED true #define INTERACTIVE false typedef long long ll; typedef unsigned long long ull; #define LOG if (LOG_ENABLED) cerr const ull INF = 1000000009ull; const int MAX_LENGTH = 100; string solveForSmall(int value) { string result = "1"; for (int i = 1; i < value; i++) { result += "+1"; } return result; } string solve(int value) { string result; if (value <= 5) { result = solveForSmall(value); } else { if (value % 2 == 0) { result = "(1+1)*(" + solve(value / 2) + ")"; } else { result = "1+" + solve(value - 1); } } return result; } void test() { int i, n; for (i = 1; i < 100; i++) { n = 1000000000 - i; // cout << "[" << n << "]: " << solve(n) << endl; cout << solve(n) << endl; } } void run() { int t, i, value; cin >> t; for (i = 0; i < t; i++) { cin >> value; cout << solve(value) << endl; } } int main() { if (true) { run(); } else { test(); } return 0; } |