結果

問題 No.3186 Big Order
ユーザー KumaTachiRen
提出日時 2025-06-20 22:18:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 76,608 KB
最終ジャッジ日時 2025-06-21 02:42:55
合計ジャッジ時間 4,147 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def calc(A, B, C):
	bs = []
	while B > 0:
		bs += [B & 1]
		B //= 2
	bs.reverse()
	x, y = 0, 1
	for b in bs:
		x += x
		if x >= 998244353: x -= 998244353
		y = y * y
		if b: y *= A
		while y % C == 0:
			y //= C
			x += 1
		if x >= 998244353: x -= 998244353
		y = math.gcd(y, C)
	return x, y

def solve():
	A, B, C = map(int, input().split())
	ans = 0
	while A % C == 0:
		A //= C
		ans += B
	A = math.gcd(A, C)
	x, y = calc(A, B, C)
	ans += x
	ans %= 998244353
	print(ans)


T = int(input())
for _ in range(T):
	solve()
0