結果

問題 No.2526 Kth Not-divisible Number
ユーザー AyunaAyuna
提出日時 2023-11-03 21:59:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 76,288 KB
最終ジャッジ日時 2023-11-03 21:59:38
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,708 KB
testcase_01 WA -
testcase_02 AC 37 ms
53,708 KB
testcase_03 AC 574 ms
76,076 KB
testcase_04 AC 576 ms
76,072 KB
testcase_05 AC 572 ms
76,076 KB
testcase_06 AC 572 ms
76,076 KB
testcase_07 AC 573 ms
76,076 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
    mn = 0
    mx = lcm
    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