結果

問題 No.1953 8
ユーザー Kude
提出日時 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
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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