結果

問題 No.3186 Big Order
ユーザー Kude
提出日時 2025-06-21 09:07:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 62,648 KB
最終ジャッジ日時 2025-06-21 09:07:10
合計ジャッジ時間 3,068 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
# def extract_commons(x, c):
#     if c == 0:
#         return x
#     c = gcd(c, x)
#     x //= c
#     while True:
#         g = gcd(c, x)
#         if g == 1:
#             return c
#         x //= g
#         c *= g

# 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