結果

問題 No.2526 Kth Not-divisible Number
ユーザー moharan627moharan627
提出日時 2023-11-03 21:36:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,054 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 77,332 KB
最終ジャッジ日時 2023-11-03 21:37:00
合計ジャッジ時間 4,494 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
55,772 KB
testcase_01 WA -
testcase_02 AC 35 ms
55,772 KB
testcase_03 AC 411 ms
76,872 KB
testcase_04 AC 386 ms
76,876 KB
testcase_05 AC 391 ms
76,868 KB
testcase_06 AC 417 ms
76,876 KB
testcase_07 AC 391 ms
76,744 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(10 ** 6)
#sys.set_int_max_str_digits(0)
INF = float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict
def ceil(A,B):
    return -(-A//B)
import math
def my_lcm(x, y):
    return (x * y) // math.gcd(x, y)
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(sys.stdin.readline().rstrip())
    def IC(): return [int(c) for c in sys.stdin.readline().rstrip()]
    def MI(): return map(int, sys.stdin.readline().split())
    T = II()

    def meguru_bisect(ng, ok):
        """
        この条件は、問題に基づくやつじゃなくてもOK
        条件の付け方は、ngとokの広げ方をどのようにするかで決まってくる。

        負の無限~(目的値)が条件を満たす場合
        ng…条件を満たさない値の範囲での最小値
        ok…条件を満たす値の範囲での最大値
        ok < ng
        is_ok == Trueの場合、探索範囲が右半分へ
        is_ok == Falseの場合、探索範囲が左半分へ

        (目的値)~正の無限 が条件を満たす場合
        ng…条件を満たさない値の範囲での最大値
        ok…条件を満たす値の範囲での最小値
        ng < ok
        is_ok == Trueの場合、探索範囲が左半分へ
        is_ok == Falseの場合、探索範囲が右半分へ
        """
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    for test in range(T):
        A,B,K = MI()
        LCM = my_lcm(A,B)
        a_num = LCM//A
        b_num = LCM//B
        k_num = LCM-(a_num+b_num-1)
        P = K//k_num
        Ans = P*LCM
        K-= k_num*P
        def is_ok(n):
            A_n = n//A
            B_n = n//B
            return K<= n-(A_n+B_n)
        add = meguru_bisect(-1,LCM)
        print(Ans+add)
    return
solve()
0