結果

問題 No.2526 Kth Not-divisible Number
ユーザー FromBooskaFromBooska
提出日時 2023-11-04 11:26:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 76,164 KB
最終ジャッジ日時 2023-11-04 11:27:00
合計ジャッジ時間 7,826 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,796 KB
testcase_01 WA -
testcase_02 AC 37 ms
53,796 KB
testcase_03 AC 635 ms
76,160 KB
testcase_04 AC 656 ms
76,164 KB
testcase_05 AC 646 ms
76,164 KB
testcase_06 AC 671 ms
76,160 KB
testcase_07 AC 634 ms
76,164 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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*2+2
    while (OK-NG)>1:
        mid = (OK+NG)//2
        if check(mid)==1:
            OK=mid
        else:
            NG=mid
    print(OK)
0