結果

問題 No.1529 Constant Lcm
ユーザー nasubi24
提出日時 2021-06-04 21:11:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,817 ms / 3,000 ms
コード長 938 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,000 KB
実行使用メモリ 92,780 KB
最終ジャッジ日時 2024-11-19 11:34:49
合計ジャッジ時間 19,975 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
class speedsbunkai:
    def __init__(self, n):
        self.num = [-1] * (n + 10)
        for i in range(2, len(self.num) + 1):
            if self.num[i - 1] == -1:
                for j in range(i, len(self.num) + 1, i):
                    if self.num[j - 1] == -1:
                        self.num[j - 1] = i
    def solve(self,n):
        ans = []
        while n != 1:
            ans.append(self.num[n - 1])
            n //= self.num[n - 1]
        return ans
n=int(input())
s=speedsbunkai(n+5)
cnt=[0]*(n+2)
for i in range(1,n):
    d=defaultdict(int)
    if i!=1:
        b=s.solve(i)
        for j in b:
            d[str(j)]+=1
    if i!=n-1:
        b=s.solve(n-i)
        for j in b:
            d[str(j)]+=1
    for k in d:
        cnt[int(k)]=max(cnt[int(k)],d.get(k))
ans=1
mod=998244353
for i in range(n+2):
    if cnt[i]>0:
        ans*=pow(i,cnt[i],mod)
        ans%=mod
print(ans)
0