結果
| 問題 | No.2497 GCD of LCMs |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-06 14:22:31 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 338 ms / 2,000 ms |
| コード長 | 1,190 bytes |
| 記録 | |
| コンパイル時間 | 301 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 78,344 KB |
| 最終ジャッジ日時 | 2024-06-24 08:48:30 |
| 合計ジャッジ時間 | 4,351 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
import sys
import heapq
MOD = 998244353
BIG = 100
n, m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
g = [[] for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
primes = set()
for i in range(n):
x = a[i]
p = 2
while p * p <= x:
if x % p == 0:
primes.add(p)
while x % p == 0:
x //= p
p += (p & 1) + 1
if x > 1:
primes.add(x)
ans = [1] * n
power = [1] * BIG
c = [0] * n
d = [0] * n
for p in primes:
for i in range(n):
c[i] = 0
x = a[i]
while x % p == 0:
c[i] += 1
x //= p
d[i] = BIG
d[0] = c[0]
pq = [[d[0], 0]]
heapq.heapify(pq)
while len(pq) > 0:
xd, x = heapq.heappop(pq)
for y in g[x]:
yd = max(c[y], xd)
if d[y] > yd:
d[y] = yd
heapq.heappush(pq, [yd, y])
power[0] = 1
for i in range(1, BIG):
power[i] = power[i - 1] * p % MOD
for i in range(n):
ans[i] = ans[i] * power[d[i]] % MOD
print("\n".join(map(str, ans)))