QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#994#634409#9456. Numbershos_lyricucup-team4967Success!2024-10-14 17:29:532024-10-14 17:29:53

Details

Extra Test:

Time Limit Exceeded

input:

20000
0 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
1 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
2 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
...

result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634409#9456. Numbersucup-team4967#TL 811ms10620kbPython3299b2024-10-12 17:15:402024-10-14 17:30:26

answer

t = int(input())

for i in range(t):
    n, m = list(map(int, input().split()))
    ans = 0
    pp = 1 << 3500
    for k in range(3500, -1, -1):
        if (pp - 1) * m < n:
            ans += pp
            cnt = min(m, n // pp)
            n -= cnt * pp
        pp >>= 1
    print(ans)