結果

問題 No.2526 Kth Not-divisible Number
ユーザー titia
提出日時 2023-11-03 21:55:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 559 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,696 KB
最終ジャッジ日時 2024-09-25 20:09:09
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import lcm

T=int(input())
for tests in range(T):
    A,B,K=map(int,input().split())
    LCM=lcm(A,B)
    # 1~LCM中に、LCM/A+LCM/B-1個が条件を満たさない

    k=LCM//A+LCM//B-1
    #print(LCM,k)
    rest=LCM-k

    x=K//rest
    ANS=x*LCM
    K-=rest*x

    #print(ANS,K)

    if K==0:
        print(ANS-1)
        continue

    OK=LCM
    NG=0

    while OK>NG+1:
        mid=(OK+NG)//2

        if mid-(mid//A)-(mid//B)>=K:
            OK=mid
        else:
            NG=mid

    print(ANS+OK)
0