結果

問題 No.2526 Kth Not-divisible Number
ユーザー 2000 Ekiben2000 Ekiben
提出日時 2024-06-30 17:52:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 494 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 84,980 KB
最終ジャッジ日時 2024-06-30 17:52:52
合計ジャッジ時間 4,269 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import math

def lcm(a, b):
    return a * b // math.gcd(a, b)

def kth(A, B, K):
    gcd_AB = math.gcd(A, B)
    high = K * (A // gcd_AB + B // gcd_AB)
    low = 1  
    
    while low < high:
        mid = (low + high) // 2
        count = mid - (mid // A) - (mid // B) + (mid // lcm(A, B))

        if count < K:
            low = mid + 1
        else:
            high = mid

    return low
T = int(input())
for _ in range(T):
    A, B, K = map(int, input().split())
    print(kth(A, B, K))
0