-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharc173-1.cpp
More file actions
60 lines (59 loc) · 1011 Bytes
/
arc173-1.cpp
File metadata and controls
60 lines (59 loc) · 1011 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
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[15], sum[15];
int ii = 1;
const int maxn = 1e12 + 1;
void init()
{
a[1] = sum[1] = 9;
int cnt = 81;
while (ii <= 14)
{
ii++;
a[ii] = cnt;
sum[ii] = cnt;
cnt *= 9;
sum[ii] += sum[ii - 1];
}
}
void solve()
{
int k;
cin >> k;
int size = lower_bound(sum + 1, sum + 15, k) - sum;
k -= sum[size - 1];
int used = 0;
int d = pow(9, size - 1);
int tar = 1;
for (int i = size - 1; i >= 0; i--)
{
int cnt = 1;
int t = (k / d);
if (k%d==0)
t--;
if (tar > used || tar + t < used)
tar += t;
else
tar += (t + 1);
cout << tar;
used = tar;
tar = 0;
k -= t * d;
d /= 9;
}
cout << endl;
return;
}
signed main()
{
init();
int t;
cin >> t;
while (t--)
{
solve();
}
system("pause");
return 0;
}