結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,364 KB
testcase_01 AC 35 ms
53,364 KB
testcase_02 AC 42 ms
59,232 KB
testcase_03 AC 35 ms
53,364 KB
testcase_04 AC 35 ms
53,364 KB
testcase_05 AC 36 ms
53,364 KB
testcase_06 AC 34 ms
53,364 KB
testcase_07 AC 35 ms
53,364 KB
testcase_08 AC 32 ms
53,364 KB
testcase_09 AC 35 ms
53,364 KB
testcase_10 AC 32 ms
53,364 KB
testcase_11 AC 34 ms
53,364 KB
testcase_12 AC 33 ms
53,364 KB
testcase_13 AC 36 ms
59,220 KB
testcase_14 AC 38 ms
59,220 KB
testcase_15 AC 37 ms
59,220 KB
testcase_16 AC 38 ms
59,228 KB
testcase_17 AC 37 ms
59,228 KB
testcase_18 AC 39 ms
59,232 KB
testcase_19 AC 40 ms
59,232 KB
testcase_20 AC 38 ms
59,232 KB
testcase_21 AC 40 ms
59,232 KB
testcase_22 AC 40 ms
59,232 KB
testcase_23 AC 40 ms
59,232 KB
testcase_24 AC 39 ms
59,232 KB
testcase_25 AC 40 ms
59,232 KB
testcase_26 AC 41 ms
59,232 KB
testcase_27 AC 39 ms
59,232 KB
testcase_28 AC 38 ms
59,220 KB
testcase_29 AC 36 ms
59,220 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