結果

問題 No.2526 Kth Not-divisible Number
ユーザー titiatitia
提出日時 2023-11-03 21:55:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 559 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 11,788 KB
実行使用メモリ 10,032 KB
最終ジャッジ日時 2023-11-03 21:56:17
合計ジャッジ時間 4,431 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,032 KB
testcase_01 AC 27 ms
10,032 KB
testcase_02 AC 28 ms
10,032 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

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