#include <iostream> #include <algorithm> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <cmath> #include <cassert> #include <cstring> #include <bitset> #include <sstream> using namespace std; #define ALL(c) c.begin(),c.end() string show(int i) { if(i==1) return "1" ; else if(i==2) return "1+1" ; else if(i==3) return "1+1+1" ; else { string nowy = (i%2) ? "1+" : "" ; return nowy + "(1+1)*(" + show(i/2) + ")" ; } } int main() { ios_base::sync_with_stdio(0) ; int a, dane ; cin >> a ; while(a--) { cin >> dane ; string res = show(dane) ; assert(count(ALL(res), '1')<=100) ; cout << res << endl ; } }
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 | #include <iostream> #include <algorithm> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <cmath> #include <cassert> #include <cstring> #include <bitset> #include <sstream> using namespace std; #define ALL(c) c.begin(),c.end() string show(int i) { if(i==1) return "1" ; else if(i==2) return "1+1" ; else if(i==3) return "1+1+1" ; else { string nowy = (i%2) ? "1+" : "" ; return nowy + "(1+1)*(" + show(i/2) + ")" ; } } int main() { ios_base::sync_with_stdio(0) ; int a, dane ; cin >> a ; while(a--) { cin >> dane ; string res = show(dane) ; assert(count(ALL(res), '1')<=100) ; cout << res << endl ; } } |