結果

問題 No.1529 Constant Lcm
ユーザー raven7959
提出日時 2021-09-27 09:20:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 780 ms / 3,000 ms
コード長 900 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,756 KB
実行使用メモリ 105,260 KB
最終ジャッジ日時 2024-07-06 04:11:28
合計ジャッジ時間 9,634 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

N=int(input())

isprime=[True]*(N+1) #isprime[i]はiが素数かどうか
isprime[1]=False
minfactor=[-1]*(N+1) #minfactor[i]はiを割り切る最小の素数
minfactor[1]=1
for p in range(2,N+1):
  if isprime[p]:
    minfactor[p]=p
    for q in range(2*p,N+1,p):
      isprime[q]=False
      if minfactor[q]==-1:
        minfactor[q]=p
def factorize(n): #nを素因数分解した時の[素因数,その指数]のリストを返す
  L=[]
  while n>1:
    p=minfactor[n]
    exp=0
    while minfactor[n]==p:
      n//=p
      exp+=1
    L.append([p,exp])
  return L

D=defaultdict(int)
for i in range(1,N//2+1):
  res=defaultdict(int)
  for p,exp in factorize(i):
    res[p]+=exp
  for p,exp in factorize(N-i):
    res[p]+=exp
  for p,exp in res.items():
    D[p]=max(D[p],exp)
ans=1
mod=998244353
for p,exp in D.items():
  ans=ans*pow(p,exp,mod)%mod
print(ans)
0