結果
| 問題 | No.2497 GCD of LCMs | 
| コンテスト | |
| ユーザー |  titia | 
| 提出日時 | 2023-10-09 01:48:27 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 384 ms / 2,000 ms | 
| コード長 | 1,046 bytes | 
| コンパイル時間 | 433 ms | 
| コンパイル使用メモリ | 82,348 KB | 
| 実行使用メモリ | 78,476 KB | 
| 最終ジャッジ日時 | 2024-07-26 18:18:43 | 
| 合計ジャッジ時間 | 4,682 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 14 | 
ソースコード
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
mod=998244353
# 素因数分解
def fact(x):
    L=round(x**(1/2)+3)
    FACT=dict()
    for i in range(2,L+2):
        while x%i==0:
            FACT[i]=FACT.get(i,0)+1
            x=x//i
    if x!=1:
        FACT[x]=FACT.get(x,0)+1
    return FACT
N,M=map(int,input().split())
A=list(map(int,input().split()))
E=[[] for i in range(N)]
for i in range(M):
    u,v=map(int,input().split())
    u-=1
    v-=1
    E[u].append(v)
    E[v].append(u)
F=[]
for a in A:
    F.append(fact(a))
ANS=[1]*N
Primes=set()
for f in F:
    for p in f:
        Primes.add(p)
for p in Primes:
    DIS=[1<<30]*N
    DIS[0]=F[0].get(p,0)
    Q=[(DIS[0],0)]
    while Q:
        dis,ind=heappop(Q)
        for to in E[ind]:
            x=F[to].get(p,0)
            if DIS[to]>max(DIS[ind],x):
                DIS[to]=max(DIS[ind],x)
                heappush(Q,(DIS[to],to))
    for i in range(N):
        ANS[i]=ANS[i]*pow(p,DIS[i],mod)%mod
for ans in ANS:
    print(ans)
            
            
            
        