結果

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

ソースコード

diff #

from math import gcd

def max_factor(a, b):
    if b == 1: return 0 if a == 1 else a
    while True:
        q, r = divmod(a, b)
        if r: break
        a = q
    while a != 1:
        while True:
            q, r = divmod(b, a)
            if r: break
            if q == 1: return a
            b = q
        q, r = divmod(a, b)
        if r == 0:
            a = q
        else:
            a = gcd(r, b)
            b //= a
    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