結果

問題 No.2526 Kth Not-divisible Number
コンテスト
ユーザー titia
提出日時 2023-11-03 21:55:57
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 559 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 560 ms
コンパイル使用メモリ 20,820 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2026-04-12 23:39:11
合計ジャッジ時間 5,220 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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