結果

問題 No.2526 Kth Not-divisible Number
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-02 19:04:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 709 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 14,584 KB
最終ジャッジ日時 2023-11-03 21:26:40
合計ジャッジ時間 4,161 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,236 KB
testcase_01 AC 25 ms
10,196 KB
testcase_02 AC 24 ms
10,196 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def gcd(a, b):
    return math.gcd(a, b)

def judge(X, A, B, C, K):
    return X - (X//A + X//B - X//C) <= K

def solve():
    A, B, K = map(int, input().split())
    assert A != B
    assert 2 <= A <= 1e9
    assert 2 <= B <= 1e9
    assert 1 <= K <= 1e18
    C = A * B // gcd(A, B)

    l = int(0)
    r = int(4e18)
    while r - l > 1:
        c = (l + r) // 2
        if judge(c, A, B, C, K):
            l = c
        else:
            r = c

    l = int(l)
    mi = max(1, l - 5)
    for X in range(mi, l + 1):
        if X - (X//A + X//B - X//C) == K and X % A != 0 and X % B != 0:
            print(X)
            return

    assert False

T = int(input())
for _ in range(T):
    solve()
0