結果

問題 No.2264 Gear Coloring
ユーザー vwxyzvwxyz
提出日時 2023-05-25 02:42:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 584 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 77,788 KB
最終ジャッジ日時 2023-08-25 16:06:31
合計ジャッジ時間 5,468 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,604 KB
testcase_01 AC 96 ms
71,752 KB
testcase_02 AC 95 ms
71,508 KB
testcase_03 AC 103 ms
76,964 KB
testcase_04 AC 95 ms
71,668 KB
testcase_05 AC 119 ms
77,660 KB
testcase_06 AC 104 ms
76,756 KB
testcase_07 AC 120 ms
77,788 KB
testcase_08 AC 101 ms
76,784 KB
testcase_09 AC 101 ms
76,728 KB
testcase_10 AC 101 ms
76,804 KB
testcase_11 AC 102 ms
76,792 KB
testcase_12 AC 102 ms
76,480 KB
testcase_13 AC 103 ms
77,264 KB
testcase_14 AC 584 ms
77,552 KB
testcase_15 AC 132 ms
77,016 KB
testcase_16 AC 493 ms
77,564 KB
testcase_17 AC 107 ms
77,412 KB
testcase_18 AC 110 ms
77,204 KB
testcase_19 AC 121 ms
77,288 KB
testcase_20 AC 110 ms
76,896 KB
testcase_21 AC 107 ms
77,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
import math
from collections import defaultdict

def Divisors(N):
    divisors=[]
    for i in range(1,N+1):
        if i**2>=N:
            break
        elif N%i==0:
            divisors.append(i)
    if i**2==N:
        divisors+=[i]+[N//i for i in divisors[::-1]]
    else:
        divisors+=[N//i for i in divisors[::-1]]
    return divisors

def Factorize(N):
    assert N>=1
    factors=defaultdict(int)
    for p in range(2,N):
        if p**2>N:
            break
        while N%p==0:
            factors[p]+=1
            N//=p
    if N!=1:
        factors[N]+=1
    return factors

def LCM(n,m):
    if n or m:
        return abs(n)*abs(m)//math.gcd(n,m)
    return 0

N,M=map(int,readline().split())
A=list(map(int,readline().split()))
mod=998244353
L=1
for a in A:
    L=LCM(L,a)
D=Divisors(L)
cnt=defaultdict(int)
for d in D:
    cnt[d]=L//d
for p in Factorize(L):
    for d in D:
        if d%p==0:
            cnt[d//p]-=cnt[d]
ans=0
for d,c in cnt.items():
    p=1
    for a in A:
        g=math.gcd(a,d)
        p*=pow(M,g,mod)
        p%=mod
    ans+=p*c
    ans%=mod
ans*=pow(L,mod-2,mod)
ans%=mod
print(ans)
0