-
Notifications
You must be signed in to change notification settings - Fork 3
/
DeciBinary_Number.cpp
77 lines (76 loc) · 1.35 KB
/
DeciBinary_Number.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define fora(i, l, r) for (int i = (int)l; i < (int)r; ++i)
#define ford(i, r, l) for (int i = (int)r; i >= (int)l; --i)
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 1;
using ll = long long;
ll N, M, K;
const ll MAXD = 22, MAXS = 300003;
ll dp[MAXD][MAXS];
ll nm[MAXS];
ll F(ll d, ll s) {
if (d == -1 && s == 0)
return 1;
if (d == -1)
return 0;
if (dp[d][s] != -1)
return dp[d][s];
dp[d][s] = 0;
fora (i, 0, 10) {
if ((1LL << d) * i > s)
break;
dp[d][s] += F(d - 1, s - (1LL << d) * i);
}
return dp[d][s];
}
void Init() {
memset(dp, -1, sizeof(dp));
fora (i, 0, MAXS) {
nm[i] = F(MAXD-1, i);
}
fora (i, 1, MAXS) {
nm[i] += nm[i-1];
}
}
void Solution() {
Init();
while (N--) {
cin >> K;
if (K == 1) cout << "0\n";
else {
auto s = lower_bound(nm, nm + MAXS, K) - nm;
ll g = K - nm[s-1];
int d = 0;
for (int i = -1; F(i, s) < g; ++i)
d = i + 1;
while (d >= 0) {
ll val = 0;
fora (i, 0, 10) {
if ((s - (1LL << d) * i) >= 0) {
val += F(d-1, s-(1LL << d) * i);
}
if (val >= g) {
cout << i;
g -= val - F(d-1, s-(1LL<<d)*i);
s -= (1LL << d) * i;
break;
}
}
--d;
}
cout << '\n';
}
}
}
int main() {
#ifdef MY_DEBUG
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
while (cin >> N) {
Solution();
}
return 0;
}