結果

問題 No.2526 Kth Not-divisible Number
コンテスト
ユーザー titia
提出日時 2023-11-03 21:56:38
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 217 ms / 2,000 ms
+ 974µs
コード長 558 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 274 ms
コンパイル使用メモリ 95,688 KB
実行使用メモリ 84,224 KB
最終ジャッジ日時 2026-09-04 08:13:10
合計ジャッジ時間 5,308 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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