結果

問題 No.3186 Big Order
ユーザー Mitarushi
提出日時 2025-06-15 12:38:37
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,332 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 81,980 KB
実行使用メモリ 75,776 KB
最終ジャッジ日時 2025-06-15 12:39:01
合計ジャッジ時間 23,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14 RE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

max_d = 132

def solve():
    a, b, c = map(int, input().split())
    assert 1 <= a <= 10 ** 40
    assert 1 <= b <= 10 ** 40
    assert 2 <= c <= 10 ** 40

    d = gcd(a, c)
    for i in range(2, 10 ** 6):
        while d % i == 0:
            d //= i
    assert d == 1

    def check(p, q):
        return a ** p % c ** q == 0
    
    if not check(max_d, 1):
        print(0)
        return

    def search():
        l = 0, 1
        u = 1, 0
        while True:
            now = check(l[0] + u[0], l[1] + u[1])
            f = u if now else l
            t = l if now else u
            k = 1
            while check(f[0] + k * 2 * t[0], f[1] + k * 2 * t[1]) == now:
                k *= 2
                if max(f[0] + k * t[0], f[1] + k * t[1]) > max_d:
                    return t
            ok = k
            ng = k * 2
            while ok + 1 < ng:
                mid = (ok + ng) // 2
                if check(f[0] + mid * t[0], f[1] + mid * t[1]) == now:
                    ok = mid
                else:
                    ng = mid
            f = f[0] + ok * t[0], f[1] + ok * t[1]
            if now:
                u = f
            else:
                l = f

    p, q = search()
    print(b * q // p % 998244353)

t = int(input())
assert 1 <= t <= 100
for _ in range(t):
    solve()
0