結果

問題 No.2526 Kth Not-divisible Number
ユーザー FromBooskaFromBooska
提出日時 2023-11-04 11:28:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 699 ms / 2,000 ms
コード長 536 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 76,316 KB
最終ジャッジ日時 2023-11-04 11:28:14
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,772 KB
testcase_01 AC 37 ms
53,772 KB
testcase_02 AC 36 ms
53,772 KB
testcase_03 AC 691 ms
76,248 KB
testcase_04 AC 660 ms
76,292 KB
testcase_05 AC 687 ms
76,248 KB
testcase_06 AC 668 ms
76,316 KB
testcase_07 AC 662 ms
76,244 KB
testcase_08 AC 671 ms
76,256 KB
testcase_09 AC 645 ms
76,252 KB
testcase_10 AC 699 ms
76,252 KB
testcase_11 AC 348 ms
76,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 二分探索と包除原理だな
# ポラード・ロー素因数分解法でもTLE

from math import lcm

def check(X):
    divisible = 0
    divisible += X//A
    divisible += X//B
    divisible -= X//AB
    if X-divisible<K:
        return 0
    else:
        return 1

T = int(input())
for t in range(T):
    A, B, K = map(int, input().split())
    AB = lcm(A, B)

    NG = 0
    OK = K*10+2
    while (OK-NG)>1:
        mid = (OK+NG)//2
        if check(mid)==1:
            OK=mid
        else:
            NG=mid
    print(OK)
0