結果

問題 No.2264 Gear Coloring
ユーザー vwxyzvwxyz
提出日時 2023-05-25 02:42:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,168 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 9,020 KB
最終ジャッジ日時 2023-08-25 16:06:44
合計ジャッジ時間 6,873 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,720 KB
testcase_01 AC 19 ms
8,716 KB
testcase_02 AC 19 ms
8,708 KB
testcase_03 AC 21 ms
8,860 KB
testcase_04 AC 19 ms
8,756 KB
testcase_05 AC 53 ms
8,972 KB
testcase_06 AC 25 ms
8,716 KB
testcase_07 AC 45 ms
8,968 KB
testcase_08 AC 21 ms
8,704 KB
testcase_09 AC 22 ms
8,884 KB
testcase_10 AC 20 ms
8,792 KB
testcase_11 AC 21 ms
8,884 KB
testcase_12 AC 23 ms
8,764 KB
testcase_13 AC 20 ms
8,704 KB
testcase_14 TLE -
testcase_15 AC 193 ms
8,860 KB
testcase_16 AC 1,946 ms
8,916 KB
testcase_17 AC 47 ms
8,800 KB
testcase_18 AC 47 ms
8,872 KB
testcase_19 AC 114 ms
8,848 KB
testcase_20 AC 36 ms
8,940 KB
testcase_21 AC 31 ms
8,876 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