結果

問題 No.2526 Kth Not-divisible Number
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-02 19:00:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 699 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 83,988 KB
最終ジャッジ日時 2023-11-03 21:24:56
合計ジャッジ時間 6,906 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
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 = 0
    r = 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