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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long f(long long m, long long x)
{
long long a = max(m, x - m), b = min(m, x - m), c = 1, d = 1;
for (int i = 1; i <= max(x - a, b); ++i)
{
if (i <= b)
d *= i;
if (i <= x - a)
c *= a + i;
if (c % d == 0)
{
c /= d;
d = 1;
}
}
return c / d;
}
pair<long long, long long> 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 (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);
}
int main()
{
long long n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
pair<long long, long long> a = bin(n, m - i);
n = n - a.second;
cout << a.first << " ";
}
return 0;
}