結果

問題 No.2526 Kth Not-divisible Number
ユーザー wgrapewgrape
提出日時 2023-12-13 09:51:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,134 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,164 KB
最終ジャッジ日時 2023-12-13 09:51:31
合計ジャッジ時間 11,261 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,588 KB
testcase_01 AC 38 ms
53,588 KB
testcase_02 AC 37 ms
53,588 KB
testcase_03 AC 1,134 ms
76,164 KB
testcase_04 AC 1,122 ms
76,160 KB
testcase_05 AC 1,131 ms
76,164 KB
testcase_06 AC 1,123 ms
76,164 KB
testcase_07 AC 1,127 ms
76,160 KB
testcase_08 AC 856 ms
76,164 KB
testcase_09 AC 750 ms
76,164 KB
testcase_10 AC 893 ms
76,164 KB
testcase_11 AC 783 ms
76,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
import math
def is_ok(x,a,b,k): # xに対して、aでもbでも割り切れない数がk個以上存在すればTrue
    g = math.gcd(a, b)
    L = a // g * b
    cnt = x - (x // a) - (x // b) + (x // L)
    return cnt >= k

for _ in range(T):
    A,B,K = map(int,input().split())
    ok = 10 ** 19
    ng = 0
    while abs(ok - ng) > 1:
        mid = abs(ok + ng) // 2
        if is_ok(mid, A, B, K):
            ok = mid
        else:
            ng = mid
    print(ok)
0