結果

問題 No.3186 Big Order
ユーザー 👑 potato167
提出日時 2025-06-20 22:28:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 79,168 KB
最終ジャッジ日時 2025-06-21 02:42:55
合計ジャッジ時間 7,019 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
MOD = 998244353
import math
def solve(a, b, c) -> tuple[int, int]:
    if b == 0:
        return (1, 0)
    if b & 1:
        tmp = solve(a, b - 1, c)
        X = tmp[0]; Y = tmp[1]
        X *= a
        while X % c == 0:
            X //= c
            Y += 1
        Y %= MOD
        X = math.gcd(X, C * C)
        return (X, Y)
    tmp = solve(a, b // 2, c)
    X = tmp[0] * tmp[0]; Y = tmp[1] * 2 % MOD
    while X % c == 0:
        X //= c
        Y += 1
    Y %= MOD
    X = math.gcd(X, C * C)
    return (X, Y)
import math
for _ in range(T):
    A, B, C = map(int, input().split())

    ans = solve(A, B, C)
    print(ans[1])
0