結果

問題 No.2497 GCD of LCMs
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-10-07 10:41:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 1,263 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 79,084 KB
最終ジャッジ日時 2023-10-07 10:41:29
合計ジャッジ時間 4,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
72,048 KB
testcase_01 AC 81 ms
76,460 KB
testcase_02 AC 82 ms
76,116 KB
testcase_03 AC 75 ms
71,772 KB
testcase_04 AC 75 ms
71,988 KB
testcase_05 AC 81 ms
71,712 KB
testcase_06 AC 87 ms
76,696 KB
testcase_07 AC 162 ms
78,116 KB
testcase_08 AC 208 ms
78,276 KB
testcase_09 AC 214 ms
78,104 KB
testcase_10 AC 315 ms
79,060 KB
testcase_11 AC 217 ms
78,624 KB
testcase_12 AC 298 ms
78,632 KB
testcase_13 AC 337 ms
78,896 KB
testcase_14 AC 236 ms
78,328 KB
testcase_15 AC 234 ms
78,180 KB
testcase_16 AC 364 ms
79,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
e = [[] for i in range(n)]
for _ in range(m):
    u,v = [int(x)-1 for x in input().split()]
    e[u].append(v)
    e[v].append(u)


divs = set()
for a in A:
    now = a
    for i in range(2,int(a**0.5)+1):
        if now%i:
            continue

        divs.add(i)
        while now%i == 0:
            now //= i

    if now != 1:
        divs.add(now)


ans = [1]*n

def calc(d,ans):

    vis = [0]*n
    ok = [0]*n
    nexs = set()

    nums = [[0,i] for i in range(n)]
    for i,a in enumerate(A):
        while a%d == 0:
            a //= d
            nums[i][0] += 1
    
    nums.sort()

    nexs.add(0)


    for num,ind in nums:
        ok[ind] = 1

        if ind not in nexs:
            continue

        vis[ind] = 1
        q = [ind]

        while q:
            now = q.pop()
            ans[now] *= pow(d,num,mod)
            ans[now] %= mod

            for nex in e[now]:
                if vis[nex]:
                    continue
                if ok[nex]:
                    vis[nex] = 1
                    q.append(nex)
                else:
                    nexs.add(nex)
    return ans

for d in divs:
    ans = calc(d,ans)

for i in ans:
    print(i)
0