結果

問題 No.1529 Constant Lcm
ユーザー roaris
提出日時 2021-06-04 21:21:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,278 ms / 3,000 ms
コード長 844 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 98,916 KB
最終ジャッジ日時 2024-11-19 12:06:08
合計ジャッジ時間 25,340 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

class Fast_factorize:
    def __init__(self, n):
        self.p = [-1]*(n+1)
        
        for i in range(2, n+1):
            if self.p[i]==-1:
                for j in range(i, n+1, i):
                    if self.p[j]==-1:
                        self.p[j] = i
    
    def factorize(self, n):
        res = []
        
        while n>1:
            res.append(self.p[n])
            n //= self.p[n]
        
        return res

N = int(input())
ff = Fast_factorize(N)
cnt = defaultdict(int)

for i in range(1, N):
    cnt1 = Counter(ff.factorize(i))
    cnt2 = Counter(ff.factorize(N-i))
    ks = set(list(cnt1.keys())+list(cnt2.keys()))
    
    for k in ks:
        cnt[k] = max(cnt[k], cnt1[k]+cnt2[k])

ans = 1
MOD = 998244353

for k, v in cnt.items():
    ans *= pow(k, v, MOD)
    ans %= MOD

print(ans)
0