結果

問題 No.1651 Removing Cards
ユーザー gew1fw
提出日時 2025-06-12 21:46:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 697 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 82,664 KB
実行使用メモリ 100,348 KB
最終ジャッジ日時 2025-06-12 21:53:32
合計ジャッジ時間 16,760 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 TLE * 3 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

def compute_p(j, K):
    q = (j - 1) // (K - 1)
    r = (j - 1) % (K - 1)
    return q * K + (r + 2)

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    K = int(input[ptr])
    ptr += 1
    Q = int(input[ptr])
    ptr += 1
    for _ in range(Q):
        N = int(input[ptr])
        ptr += 1
        if N == 1:
            print(1)
            continue
        M_list = []
        M = N
        while M > 1:
            M_list.append(M)
            s = (M - 1) // K + 1
            M = M - s
        M_list.append(1)
        j = 1
        for i in reversed(range(len(M_list) - 1)):
            j = compute_p(j, K)
        print(j)

if __name__ == "__main__":
    main()
0