#include <cstdio> #include <iostream> #include <vector> #include <list> #include <string> #include <set> #include <map> #include <algorithm> #include <utility> #include <cmath> #include <queue> #include <stack> #include <cassert> #include <cstring> #include <climits> #include <functional> #include <unordered_set> #include <unordered_map> #define VAR(i,v) __typeof(v) i = (v) #define SIZE(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define REP(i,b) for(int i=0; i<(b); ++i) #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORD(i,a,b) for(int i=(a); i>=(b); --i) #define FOREACH(i,c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define PB push_back #define MP make_pair #define ST first #define ND second #define NL printf("\n") using namespace std; typedef pair<int,int> PII; typedef vector<int> VI; typedef long long LL; int less_power(int x) { if(x == 0) return 0; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return (x>>1) + 1; } int ilog(int x) { int result = 0; if(x == 1) return 0; while(x > 1) { x /= 2; result++; } return result; } string power_to_string(int p) { if(p == 0) return "(1)"; string res = ""; REP(i,p) { res += "(1+1)"; if(i < p-1) res += "*"; } return res; } int main() { int t; scanf("%d", &t); REP(i,t) { int x; scanf("%d", &x); string res = ""; VI bin; while(x > 0) { bin.PB(x%2); x /= 2; } reverse(ALL(bin)); res = "1"; FOR(i,1,SIZE(bin)-1) { res += "*(1+1)"; if(bin[i] == 1) res += "+1"; res.insert(0,"("); res += ")"; } int ones = 0; for(char x: res) if(x == '1') ones++; if(ones <= 100) printf("%s\n", res.c_str()); else printf("NIE\n"); } 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 96 97 98 | #include <cstdio> #include <iostream> #include <vector> #include <list> #include <string> #include <set> #include <map> #include <algorithm> #include <utility> #include <cmath> #include <queue> #include <stack> #include <cassert> #include <cstring> #include <climits> #include <functional> #include <unordered_set> #include <unordered_map> #define VAR(i,v) __typeof(v) i = (v) #define SIZE(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define REP(i,b) for(int i=0; i<(b); ++i) #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORD(i,a,b) for(int i=(a); i>=(b); --i) #define FOREACH(i,c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define PB push_back #define MP make_pair #define ST first #define ND second #define NL printf("\n") using namespace std; typedef pair<int,int> PII; typedef vector<int> VI; typedef long long LL; int less_power(int x) { if(x == 0) return 0; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return (x>>1) + 1; } int ilog(int x) { int result = 0; if(x == 1) return 0; while(x > 1) { x /= 2; result++; } return result; } string power_to_string(int p) { if(p == 0) return "(1)"; string res = ""; REP(i,p) { res += "(1+1)"; if(i < p-1) res += "*"; } return res; } int main() { int t; scanf("%d", &t); REP(i,t) { int x; scanf("%d", &x); string res = ""; VI bin; while(x > 0) { bin.PB(x%2); x /= 2; } reverse(ALL(bin)); res = "1"; FOR(i,1,SIZE(bin)-1) { res += "*(1+1)"; if(bin[i] == 1) res += "+1"; res.insert(0,"("); res += ")"; } int ones = 0; for(char x: res) if(x == '1') ones++; if(ones <= 100) printf("%s\n", res.c_str()); else printf("NIE\n"); } return 0; } |