結果

問題 No.2526 Kth Not-divisible Number
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-11-03 22:18:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 593 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 76,780 KB
最終ジャッジ日時 2023-11-03 22:18:36
合計ジャッジ時間 5,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
53,576 KB
testcase_01 WA -
testcase_02 AC 30 ms
53,576 KB
testcase_03 AC 424 ms
76,212 KB
testcase_04 AC 442 ms
76,312 KB
testcase_05 AC 419 ms
76,308 KB
testcase_06 AC 422 ms
76,332 KB
testcase_07 AC 447 ms
76,308 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def calc(m,a,b,ab):

    return m - m//a - m//b + m//ab
def solve():

    a,b,k = map(int,input().split())
    ab = a*b//(gcd(a,b))

    base = ab - ab//a - ab//b + 1

    l = max((k-1)//base * ab-ab,0)
    assert calc(l,a,b,ab) < k
    r = l + 2*ab

    # assert calc(r,a,b,ab) > k

    while r - l > 1:

        m = (r+l)//2

        num = m

        num -= m//a + m//b
        num += m//ab

        if num > k:
            r = m
        else:
            l = m

    return l

t = int(input())
for _ in range(t):
    print(solve())
0