結果

問題 No.3186 Big Order
ユーザー Kude
提出日時 2025-06-21 09:09:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2025-06-21 09:09:19
合計ジャッジ時間 2,777 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

# returns prod of scaled factors with slope (vp(a),vb(b)) max, assuming slope (0,0)=-inf
# i.e. prod_{(vp(a),vp(b))//(s,t)} p^((vp(a)+vp(b))/(s+t)), where slope (s,t) is max
# if a=b=1, returns 0
def max_factor(a, b):
    if b == 1: return 0 if a == 1 else a
    while a != 1:
        if a % b == 0: a //= b
        elif b % a == 0: b //= a
        else: a = gcd(a, b)
    return b

def solve(a, b, c):
    ans = 0
    f = max_factor(a, c)
    ea = ec = 0
    while a % f == 0:
        a //= f
        ea += 1
    while c % f == 0:
        c //= f
        ec += 1
    return ans + ea * b // ec

for _ in range(int(input())):
    print(solve(*map(int, input().split())) % 998244353)
0