結果

問題 No.2526 Kth Not-divisible Number
ユーザー AyunaAyuna
提出日時 2023-11-03 22:07:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 76,536 KB
最終ジャッジ日時 2023-11-03 22:07:26
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,684 KB
testcase_01 AC 37 ms
53,684 KB
testcase_02 AC 37 ms
53,684 KB
testcase_03 AC 583 ms
76,076 KB
testcase_04 AC 495 ms
76,080 KB
testcase_05 AC 532 ms
76,076 KB
testcase_06 AC 518 ms
76,076 KB
testcase_07 AC 546 ms
76,076 KB
testcase_08 AC 340 ms
76,328 KB
testcase_09 AC 363 ms
76,536 KB
testcase_10 AC 382 ms
76,084 KB
testcase_11 AC 302 ms
76,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
t = int(input())

def check(mid, r, a, b):
    if mid - (mid // a + mid // b) >= r:
        return True
    return False

for _ in range(t):
    a, b, k = map(int, input().split())
    lcm = a * b // math.gcd(a, b)
    wareru = lcm // a + lcm // b - 1
    d, r = divmod(k, lcm - wareru)
    if r == 0:
        print(d * lcm - 1)
        continue
    mn = 0
    mx = lcm - 1
    while mx - mn > 1:
        mid = (mx + mn) // 2
        if check(mid, r, a, b): # midは小さい方からr番目以上
            mx = mid
        else:
            mn = mid
        
    print(d * lcm + mx)
0