Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #define lmao ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5. #define pii pair<int, int>
  6. #define int int64_t
  7. #define pdd pair<double, double>
  8. #define double long double
  9. #define F first
  10. #define S second
  11. #define pb push_back
  12. #define ff(i, n) for(int i = 0; i < n; i ++)
  13. using namespace std;
  14. using namespace __gnu_pbds;
  15.  
  16. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  17.  
  18. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  19.  
  20. int lol;
  21.  
  22. void magic(vector<string>& result){
  23.    if(result[result.size()-2] == ")" && result.size() >= 2) {
  24.       -- lol;
  25.       result.erase(result.begin() + result.size() - 2);
  26.    }
  27.    if(result.back() == ")") {
  28.       -- lol;
  29.       result.pop_back();
  30.    }
  31. }
  32.  
  33. int32_t main() { lmao
  34.    ordered_set a, b;
  35. //   a.insert(d);
  36. //   cout << b.find_by_order
  37.    vector<string> result;
  38.    int n, d;
  39.    cin >> n >> d;
  40.    string add = "", kek = "";
  41.    add.pb((char)(d + '0'));
  42.    if(n % d > 0){
  43.       cout << "no solution";
  44.       return 0;
  45.    }
  46.    if(d == 1){
  47.       d = 2;
  48.       for(int i = 0; i < n % 2; i ++) {
  49.          result.pb("1");
  50.          result.pb("+");
  51.       }
  52.       add = "(1";
  53.       add += "+1";
  54.       add += ")";
  55.    }
  56.    n /= d;
  57.    for(; n >= 1 && result.size() <= 1000;) {
  58.       if(n >= 1 && n % d == 0) {
  59.          result.pb(add);
  60.          result.pb("*");
  61.          n /= d;
  62.       }
  63.       for(; n >= 1 && n % d >= 1; ) {
  64.          result.pb(")");
  65.          result.pb(add);
  66.          result.pb("+");
  67.          -- n; lol ++;
  68.       }
  69.    }
  70.    result.pop_back();
  71.    magic(result);
  72.    for(int i = 0; i < lol; i ++)
  73.       result.pb("(");
  74.  
  75.    int kekandos = 0;
  76.    for(int i = 0; i < result.size(); i ++){
  77.       kekandos += result[i].size();
  78.    }
  79.    if(kekandos > 1000){
  80.       cout << "Mda...";
  81.       exit(0);
  82.    }
  83.  
  84.    if(n == 0){
  85.       reverse(result.begin(), result.end());
  86.       for(int i = 0; i < result.size(); i ++)
  87.          cout << result[i];
  88.    }else{
  89.       cout << "no solution";
  90.    }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement