結果

問題 No.2526 Kth Not-divisible Number
ユーザー titiatitia
提出日時 2023-11-03 21:56:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 76,308 KB
最終ジャッジ日時 2023-11-03 21:56:44
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,732 KB
testcase_01 AC 39 ms
53,732 KB
testcase_02 AC 37 ms
53,732 KB
testcase_03 AC 367 ms
76,072 KB
testcase_04 AC 374 ms
76,208 KB
testcase_05 AC 376 ms
76,080 KB
testcase_06 AC 378 ms
76,196 KB
testcase_07 AC 375 ms
76,188 KB
testcase_08 AC 174 ms
76,308 KB
testcase_09 AC 150 ms
76,104 KB
testcase_10 AC 210 ms
76,068 KB
testcase_11 AC 164 ms
76,060 KB
権限があれば一括ダウンロードができます

ソースコード

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