結果

問題 No.294 SuperFizzBuzz
ユーザー maspymaspy
提出日時 2020-03-17 15:26:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 884 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 11,072 KB
最終ジャッジ日時 2023-08-20 18:45:36
合計ジャッジ時間 1,861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,784 KB
testcase_01 AC 34 ms
10,916 KB
testcase_02 AC 35 ms
10,880 KB
testcase_03 AC 35 ms
10,900 KB
testcase_04 AC 35 ms
10,800 KB
testcase_05 AC 35 ms
10,764 KB
testcase_06 AC 35 ms
10,872 KB
testcase_07 AC 35 ms
10,816 KB
testcase_08 AC 35 ms
10,816 KB
testcase_09 AC 35 ms
10,884 KB
testcase_10 AC 35 ms
10,912 KB
testcase_11 AC 35 ms
11,036 KB
testcase_12 AC 35 ms
11,072 KB
testcase_13 AC 35 ms
10,892 KB
testcase_14 AC 35 ms
11,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache


# %%
@lru_cache(None)
def f(N, i):
    """1以上N以下のうち、3と5のみからなり、mod 3 で i のものを数える"""
    if N < 10:
        if N >= 3 and i == 0:
            return 1
        if N >= 5 and i == 2:
            return 1
        return 0
    ret = 0
    if i in [0, 2]:
        ret = 1
    ret += f((N - 3) // 10, i)
    ret += f((N - 5) // 10, (i - 5) % 3)
    return ret


def cnt_super_fz(N):
    return f((N - 5) // 10, 1)


def solve(K):
    left = 0
    right = 10 ** 50
    while left + 1 < right:
        x = (left + right) // 2
        if cnt_super_fz(x) >= K:
            right = x
        else:
            left = x
    return right


# %%
print(solve(int(read())))
0