#include<bits/stdc++.h> #define int long long #define endl '\n' usingnamespace std;
int n; int sum = 0, p = 1; vector<vector<string>> dp; vector<vector<bool>> choose;
voidprintpath(){ vector<int> path; int i = p ,j = n; while(i > 0 && j > 0){ if(choose[i][j]){ path.push_back(i); j -= i; i -= 1; } else{ i -= 1; } } reverse(path.begin(),path.end()); for(int k : path) cout << k << " "; cout << endl; }
string jjmul(const string &a, const string &b){ if (a == "0" || b == "0") return"0"; int la = a.size(), lb = b.size(); vector<int> re(la + lb, 0); for (int i = la - 1; i >= 0; i--) { int x = a[i] - '0'; for (int j = lb - 1; j >= 0; j--) { int y = b[j] - '0'; int mul = x * y + re[i + j + 1]; re[i + j + 1] = mul % 10; re[i + j] += mul / 10; } } string ans; ans.reserve(la + lb); for (int d : re) { ans.push_back(char(d + '0')); } ans.erase(0, ans.find_first_not_of('0')); if (ans.empty()) ans = "0"; return ans; }
boolcmpbig(const string &a, const string &b){ int la = a.size(),lb = b.size(); if(la > lb) returntrue; elseif(la < lb) returnfalse; else{ return a > b; } }
#include<bits/stdc++.h> #define int long long #define endl '\n' usingnamespace std;
int n; int sum = 0, p = 1; vector<vector<longdouble>> dp; vector<vector<bool>> choose;
vector<int> getpath(){ vector<int> path; int i = p, j = n; while (i > 0 && j > 0) { if (choose[i][j]) { path.push_back(i); j -= i; i -= 1; } else { i -= 1; } } reverse(path.begin(), path.end()); return path; }
string jjmul(const string &a, const string &b){ if (a == "0" || b == "0") return"0"; int la = a.size(), lb = b.size(); vector<int> re(la + lb, 0); for (int i = la - 1; i >= 0; i--) { int x = a[i] - '0'; for (int j = lb - 1; j >= 0; j--) { int y = b[j] - '0'; int mul = x * y + re[i + j + 1]; re[i + j + 1] = mul % 10; re[i + j] += mul / 10; } } string ans; ans.reserve(la + lb); for (int d : re) { ans.push_back(char(d + '0')); } ans.erase(0, ans.find_first_not_of('0')); if (ans.empty()) ans = "0"; return ans; }
signedmain(){ ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; while (sum < n) { p++; sum += p; } constlongdouble NEG = -1e100L; dp.assign(p + 1, vector<longdouble>(n + 1, NEG)); choose.assign(p + 1, vector<bool>(n + 1, false)); dp[0][0] = 0.0L; for (int i = 1; i <= p; i++) { for (int j = 0; j <= n; j++) { dp[i][j] = dp[i - 1][j]; choose[i][j] = false; if (i >= 2 && j >= i && dp[i - 1][j - i] != NEG) { longdouble t = dp[i - 1][j - i] + logl((longdouble)i); //logl是取自然对数 if (t > dp[i][j] + 1e-15L) { // 浮点容忍 // 累加对数时,每一次 logl()、加法、本身的二进制表示都会引入一点点舍入误差 dp[i][j] = t; choose[i][j] = true; } } } } vector<int> path = getpath(); for (size_t k = 0; k < path.size(); ++k) { if (k) cout << " "; cout << path[k]; } cout << endl; string ans = "1"; for(int i : path){ ans = jjmul(ans ,to_string(i)); } cout << ans << endl; return0; }