結果

問題 No.2526 Kth Not-divisible Number
ユーザー chineristACchineristAC
提出日時 2023-11-03 22:24:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 81,752 KB
実行使用メモリ 83,116 KB
最終ジャッジ日時 2023-11-03 22:25:06
合計ジャッジ時間 6,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
66,852 KB
testcase_01 AC 63 ms
66,852 KB
testcase_02 AC 52 ms
66,852 KB
testcase_03 AC 483 ms
82,460 KB
testcase_04 AC 479 ms
82,428 KB
testcase_05 AC 509 ms
82,472 KB
testcase_06 AC 498 ms
82,456 KB
testcase_07 AC 502 ms
82,464 KB
testcase_08 AC 465 ms
82,524 KB
testcase_09 AC 400 ms
82,480 KB
testcase_10 AC 488 ms
82,420 KB
testcase_11 AC 373 ms
83,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod


mod = 998244353
N = 2*10**5
g1 = [1]*(N+1)
g2 = [1]*(N+1)
inverse = [1]*(N+1)

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

from math import gcd

def solve(A,B,K):
    lcm = A*B//gcd(A,B)
    def cond(x):
        tmp = x - x//A - x//B + x//lcm
        return K <= tmp
    
    ok = 10**18 * 8
    ng = 0
    while ok-ng>1:
        mid = (ok+ng)//2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

for _ in range(int(input())):
    a,b,k = mi()
    print(solve(a,b,k))
0