結果

問題 No.1396 Giri
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-17 17:03:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 601 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 160,504 KB
最終ジャッジ日時 2023-08-31 00:15:21
合計ジャッジ時間 9,733 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,736 KB
testcase_01 AC 90 ms
72,100 KB
testcase_02 AC 601 ms
160,408 KB
testcase_03 AC 91 ms
72,084 KB
testcase_04 AC 91 ms
71,964 KB
testcase_05 AC 584 ms
160,432 KB
testcase_06 AC 90 ms
71,848 KB
testcase_07 AC 88 ms
72,012 KB
testcase_08 AC 89 ms
72,084 KB
testcase_09 AC 91 ms
71,992 KB
testcase_10 AC 90 ms
71,788 KB
testcase_11 AC 90 ms
71,728 KB
testcase_12 AC 90 ms
71,996 KB
testcase_13 AC 90 ms
72,040 KB
testcase_14 AC 90 ms
71,732 KB
testcase_15 AC 91 ms
72,148 KB
testcase_16 AC 108 ms
77,968 KB
testcase_17 AC 118 ms
78,080 KB
testcase_18 AC 144 ms
83,372 KB
testcase_19 AC 361 ms
118,960 KB
testcase_20 AC 451 ms
136,064 KB
testcase_21 AC 533 ms
151,396 KB
testcase_22 AC 581 ms
160,504 KB
testcase_23 AC 586 ms
160,376 KB
testcase_24 AC 588 ms
160,376 KB
testcase_25 AC 584 ms
160,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
mod=998244353

# エラトステネスの篩。高速素因数分解ver
# ret[x]:xを篩い落とす最大の素数。xが素数ならxが入る
# ret[ii]=min(i,ret[ii])とすれば最小の整数が入る。
def eratosthenes(n):
  ret=list(range(n+1))
  for i in range(2,int(n**.5)+1):
    if ret[i]!=i:continue
    ii=i
    while ii<=n:
      ret[ii]=i
      ii+=i
  return ret
# 例:x(<=n)を素因数分解する
from collections import defaultdict
d=eratosthenes(n)
mxp=n
for i in reversed(range(n+1)):
  if d[i]==i:
    mxp=i
    break
nums=[i for i in range(1,n+1) if i!=mxp]
cnt={}
for x in nums:
  c={}
  while x!=1:
    if d[x] in c:
      c[d[x]]+=1
    else:
      c[d[x]]=1
    x//=d[x]
  for k,v in c.items():
    if k in cnt:
      cnt[k]=max(cnt[k],v)
    else:
      cnt[k]=v
ans=1
for k,v in cnt.items():
  ans=ans*pow(k,v,mod)%mod
print(ans)
0