Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define lmao ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define pii pair<int, int>
- #define int int64_t
- #define pdd pair<double, double>
- #define double long double
- #define F first
- #define S second
- #define pb push_back
- #define ff(i, n) for(int i = 0; i < n; i ++)
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- int lol;
- void magic(vector<string>& result){
- if(result[result.size()-2] == ")" && result.size() >= 2) {
- -- lol;
- result.erase(result.begin() + result.size() - 2);
- }
- if(result.back() == ")") {
- -- lol;
- result.pop_back();
- }
- }
- int32_t main() { lmao
- ordered_set a, b;
- // a.insert(d);
- // cout << b.find_by_order
- vector<string> result;
- int n, d;
- cin >> n >> d;
- string add = "", kek = "";
- add.pb((char)(d + '0'));
- if(n % d > 0){
- cout << "no solution";
- return 0;
- }
- if(d == 1){
- d = 2;
- for(int i = 0; i < n % 2; i ++) {
- result.pb("1");
- result.pb("+");
- }
- add = "(1";
- add += "+1";
- add += ")";
- }
- n /= d;
- for(; n >= 1 && result.size() <= 1000;) {
- if(n >= 1 && n % d == 0) {
- result.pb(add);
- result.pb("*");
- n /= d;
- }
- for(; n >= 1 && n % d >= 1; ) {
- result.pb(")");
- result.pb(add);
- result.pb("+");
- -- n; lol ++;
- }
- }
- result.pop_back();
- magic(result);
- for(int i = 0; i < lol; i ++)
- result.pb("(");
- int kekandos = 0;
- for(int i = 0; i < result.size(); i ++){
- kekandos += result[i].size();
- }
- if(kekandos > 1000){
- cout << "Mda...";
- exit(0);
- }
- if(n == 0){
- reverse(result.begin(), result.end());
- for(int i = 0; i < result.size(); i ++)
- cout << result[i];
- }else{
- cout << "no solution";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement