Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. #define pb push_back
  7. #define mp make_pair
  8. #define forn(i, a, n) for (auto (i) = (a); (i) < (n); ++i)
  9. #define int ll
  10. #define fs first
  11. #define sc second
  12.  
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. typedef long double ld;
  16. const int maxn = 1e5 + 7;
  17. const int inf = 1e9 + 7;
  18. const ld eps = 1e-6;
  19. string dp[10000];
  20. signed main() {
  21.     ios_base::sync_with_stdio(0);
  22.     cin.tie(0); cout.tie(0);
  23.     int n;
  24.     cin >> n;
  25.     forn (i, 0, 2) {
  26.         forn (j, 0, 2) {
  27.             forn (k, 0, 2) {
  28.                 forn (l, 0, 2) {
  29.                     string x = "";
  30.                     int ind = 0;
  31.                     if (!i) {
  32.                         x += '2';
  33.                         ind += 2000;
  34.                     }
  35.                     else {
  36.                         x += '3';
  37.                         ind += 3000;
  38.                     }
  39.                     if (!j) {
  40.                         x += '2';
  41.                         ind += 200;
  42.                     }
  43.                     else {
  44.                         x += '3';
  45.                         ind += 300;
  46.                     }
  47.                     if (!k) {
  48.                         x += '2';
  49.                         ind += 20;
  50.                     }
  51.                     else {
  52.                         x += '3';
  53.                         ind += 30;
  54.                     }
  55.                     if (!l) {
  56.                         x += '2';
  57.                         ind += 2;
  58.                     }
  59.                     else {
  60.                         x += '3';
  61.                         ind += 3;
  62.                     }
  63.                     dp[ind] = x;
  64.                 }
  65.             }
  66.         }
  67.     }
  68.     forn (i, 0, 2) {
  69.         forn (j, 0, 2) {
  70.             forn (k, 0, 2) {
  71.                 string x = "";
  72.                 int ind = 0;
  73.                 if (!i) {
  74.                     ind += 200;
  75.                     x += '2';
  76.                 }
  77.                 else {
  78.                     ind  += 300;
  79.                     x += '3';
  80.                 }
  81.                 if (!j) {
  82.                     ind += 20;
  83.                     x += '2';
  84.                 }
  85.                 else {
  86.                     ind += 30;
  87.                     x += '3';
  88.                 }
  89.                 if (!k) {
  90.                     ind += 2;
  91.                     x += '2';
  92.                 }
  93.                 else {
  94.                     ind += 3;
  95.                     x += 3;
  96.                 }
  97.                 dp[ind] = x;
  98.             }
  99.         }
  100.     }
  101.     dp[22] = "22";
  102.     dp[23] = "23";
  103.     dp[32] = "32";
  104.     dp[33] = "33";
  105.     dp[3] = "3";
  106.     dp[2] = "2";
  107.     forn (i, 0, 10000) {
  108.         if (dp[i] == "")
  109.             continue ;
  110.         forn (j, 0, 10000) {
  111.             if (dp[j] == "")
  112.                 continue ;
  113.             int ind = i * j;
  114.             if (ind >= 10000)
  115.                 break ;
  116.             if (dp[i * j].size() > dp[i].size() + 1 + dp[j].size() || dp[i * j] == "") {
  117.                 dp[i * j] = dp[i];
  118.                 dp[i * j] += '*';
  119.                 dp[i * j] += dp[j];
  120.             }
  121.         }
  122.     }
  123.     forn (i, 0, 10000) {
  124.         if (dp[i] == "")
  125.             continue ;
  126.         forn (j, 0, 10000) {
  127.             if (dp[j] == "")
  128.                 continue ;
  129.             int ind = i + j;
  130.             if (ind >= 10000)
  131.                 break ;
  132.             if (dp[i + j].size() > (dp[i].size() + dp[j].size() + 1) || dp[i + j] == "") {
  133.                 dp[i + j] = dp[i];
  134.                 dp[i + j] += '+';
  135.                 dp[i + j] += dp[j];
  136.             }
  137.         }
  138.     }
  139.     if (dp[n] == "") {
  140.         cout << "No solution";
  141.     }
  142.     else {
  143.         cout << dp[n];
  144.     }
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement