結果

問題 No.1953 8
ユーザー KudeKude
提出日時 2022-05-20 23:57:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,944 KB
実行使用メモリ 61,176 KB
最終ジャッジ日時 2024-09-20 10:23:15
合計ジャッジ時間 4,757 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,684 KB
testcase_01 AC 36 ms
53,140 KB
testcase_02 AC 40 ms
61,108 KB
testcase_03 AC 35 ms
53,456 KB
testcase_04 AC 35 ms
52,432 KB
testcase_05 AC 37 ms
52,692 KB
testcase_06 AC 35 ms
52,284 KB
testcase_07 AC 35 ms
52,312 KB
testcase_08 AC 35 ms
52,708 KB
testcase_09 AC 35 ms
52,204 KB
testcase_10 AC 35 ms
52,868 KB
testcase_11 AC 36 ms
53,988 KB
testcase_12 AC 35 ms
53,164 KB
testcase_13 AC 39 ms
58,036 KB
testcase_14 AC 38 ms
59,336 KB
testcase_15 AC 41 ms
58,920 KB
testcase_16 AC 40 ms
59,856 KB
testcase_17 AC 38 ms
58,776 KB
testcase_18 AC 38 ms
59,272 KB
testcase_19 AC 41 ms
59,504 KB
testcase_20 AC 41 ms
60,704 KB
testcase_21 AC 40 ms
60,908 KB
testcase_22 AC 41 ms
59,500 KB
testcase_23 AC 40 ms
59,716 KB
testcase_24 AC 41 ms
60,072 KB
testcase_25 AC 41 ms
60,760 KB
testcase_26 AC 41 ms
61,176 KB
testcase_27 AC 41 ms
60,924 KB
testcase_28 AC 40 ms
58,860 KB
testcase_29 AC 42 ms
58,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

d = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1]
s = [0] * 11
for i in range(10):
    s[i+1] = s[i] + d[i]

def g(n):
    res = 0
    while n:
        res += d[n % 10]
        n //= 10
    return res

def f(n):
    if n == 0:
        return 0
    x = n // 10
    y = n % 10
    if x == 0:
        return s[y]
    res = s[y] + x * s[10]
    res += g(x) * y + (f(x) - 1) * 10
    return res

k = int(input()) + 1
l = 0
r = 1
while f(r) <= k:
    l = r
    r *= 2
while r - l > 1:
    c = l + r >> 1
    if f(c) <= k:
        l = c
    else:
        r = c
if f(l) == k:
    print(l - 1)
else:
    print(-1)
0