# include iostream include vector include algorithm using namespace std

 ``` 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107``` ```#include #include #include using namespace std; long long f(long long m, long long x) { double ans = 1; for (int i = 1; i <= x - max(x - m, m); ++i) ans *= (x - max(x - m, m) + i) / i; return floor(ans + 0.1); } pair bin(long long n, long long m) { //long long l = 1, r = 10000000, x = (l + r)/2, a = f(m, x), b = f(m, x + 1); long long x = m, a = f(m, x), b = f(m, x + 1); while (!(a <= n && b > n)) { if (!n) return make_pair(m - 1, 0); /*if (a > n) r = x; else l = x; x = (l + r)/2; */ x++; a = b; //a = f(m, x); b = f(m, x + 1); } return make_pair(x, a); } pair bin_1(long long n, long long m) { long long x = m, a = f(m, x), b, inc = 1; while (1) { if (!n) return make_pair(m - 1, 0); b = a; a = f(m, x + inc); if (a == n) return make_pair(x + inc, a); if (a > n && b < n) return make_pair(x, b); if (a > n) inc /= 2; else inc *= 2; } return make_pair(x + inc, a); } pair bin_2(long long n, long long m) { long long x = 1, inc = 1, a = x * (x - 1) / 2, b = x * (x + 1) / 2; while (!(a <= n && b > n)) { if (!n) return make_pair(m - 1, 0); if (b < n) { x += inc; inc *= 2; } else { x -= inc / 2; inc = 1; } a = x * (x - 1) / 2; b = x * (x + 1) / 2; } return make_pair(x, a); } int main() { long long n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { pair a; if (m - i == 1) cout << n << endl; else if (m - i == 2) { a = bin_2(n, 2); n = n - a.second; cout << a.first << " "; } else { a = bin(n, m - i); n = n - a.second; cout << a.first << " "; } } return 0; } ```