結果

問題 No.1651 Removing Cards
ユーザー tassei903tassei903
提出日時 2021-08-20 22:48:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 97,912 KB
最終ジャッジ日時 2024-04-22 05:45:06
合計ジャッジ時間 7,694 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,096 KB
testcase_01 AC 39 ms
52,224 KB
testcase_02 AC 59 ms
75,648 KB
testcase_03 AC 40 ms
52,224 KB
testcase_04 AC 40 ms
52,480 KB
testcase_05 AC 40 ms
52,352 KB
testcase_06 AC 41 ms
52,480 KB
testcase_07 AC 40 ms
51,968 KB
testcase_08 AC 41 ms
52,864 KB
testcase_09 AC 125 ms
76,544 KB
testcase_10 AC 127 ms
76,416 KB
testcase_11 AC 128 ms
76,160 KB
testcase_12 AC 125 ms
76,160 KB
testcase_13 AC 128 ms
76,288 KB
testcase_14 AC 126 ms
75,904 KB
testcase_15 AC 192 ms
95,488 KB
testcase_16 AC 196 ms
95,348 KB
testcase_17 AC 195 ms
95,512 KB
testcase_18 AC 196 ms
95,104 KB
testcase_19 AC 194 ms
95,104 KB
testcase_20 AC 190 ms
95,260 KB
testcase_21 AC 196 ms
95,360 KB
testcase_22 AC 155 ms
97,912 KB
testcase_23 AC 117 ms
75,776 KB
testcase_24 AC 111 ms
76,124 KB
testcase_25 AC 167 ms
97,664 KB
testcase_26 AC 167 ms
95,232 KB
testcase_27 AC 184 ms
97,408 KB
testcase_28 AC 187 ms
97,536 KB
testcase_29 AC 197 ms
97,536 KB
testcase_30 AC 196 ms
97,664 KB
testcase_31 AC 206 ms
97,408 KB
testcase_32 AC 125 ms
76,444 KB
testcase_33 AC 128 ms
76,720 KB
testcase_34 AC 127 ms
76,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
inf = 10**16
#######################################################################
k, q = na()

from bisect import *
bl = bisect_left
br = bisect_right


def f(n):
    r = 0
    while True:
        #print(n)
        if n%k==0:
            break
        n = n-(n+k-1)//k
        r+=1
    return r

def g(n):
    r = []
    while n>0:
        r.append(str(n%k))
        n//=k
    return "".join(r[::-1])

def solve(n):
    return 1-ans[bl(ans, -n)]
"""i = 0
j = 1
ans = []
m = -1
N = 10**3
while i<N:
    z = f(i)
    if m<z:
        m = z
        ans.append(i)
    i+=1
"""
dp = [0]
while dp[-1]<=10**18:
    dp.append((dp[-1]*k+k-1)//(k-1))
        
ans = [-i for i in dp][::-1]

for i in range(q):
    n = ni()-1
    print(solve(n))
0