-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharc-std.cpp
More file actions
51 lines (48 loc) · 942 Bytes
/
arc-std.cpp
File metadata and controls
51 lines (48 loc) · 942 Bytes
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
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
void solve()
{
ll K;
cin >> K;
K--;
ll cnt = 1;
int d = 0;
while (true)
{
d++;
cnt *= 9;
if (K >= cnt)
{
K -= cnt;
}
else
{
vector<int> digits;
for (int i = 0; i < d; i++)
{
digits.push_back(K % 9);
K /= 9;
}
reverse(digits.begin(), digits.end());
digits[0]++;
for (int i = 1; i < d; i++)
{
if (digits[i] >= digits[i - 1])
digits[i]++;
}
for (int a : digits)
cout << a;
cout << '\n';
break;
}
}
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int T;
cin >> T;
while (T--)
solve();
}