結果

問題 No.1529 Constant Lcm
ユーザー roarisroaris
提出日時 2021-06-04 21:21:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,330 ms / 3,000 ms
コード長 844 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 101,284 KB
最終ジャッジ日時 2023-08-12 11:25:20
合計ジャッジ時間 26,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,420 KB
testcase_01 AC 155 ms
78,576 KB
testcase_02 AC 87 ms
71,444 KB
testcase_03 AC 82 ms
71,392 KB
testcase_04 AC 87 ms
71,504 KB
testcase_05 AC 89 ms
71,388 KB
testcase_06 AC 91 ms
71,584 KB
testcase_07 AC 84 ms
71,576 KB
testcase_08 AC 88 ms
71,536 KB
testcase_09 AC 80 ms
71,512 KB
testcase_10 AC 1,971 ms
100,096 KB
testcase_11 AC 839 ms
86,340 KB
testcase_12 AC 171 ms
80,412 KB
testcase_13 AC 1,693 ms
96,264 KB
testcase_14 AC 1,090 ms
90,524 KB
testcase_15 AC 1,163 ms
91,804 KB
testcase_16 AC 909 ms
88,668 KB
testcase_17 AC 551 ms
83,668 KB
testcase_18 AC 607 ms
84,920 KB
testcase_19 AC 1,097 ms
89,360 KB
testcase_20 AC 2,189 ms
101,284 KB
testcase_21 AC 2,320 ms
100,164 KB
testcase_22 AC 2,282 ms
99,756 KB
testcase_23 AC 2,204 ms
100,892 KB
testcase_24 AC 2,330 ms
100,436 KB
testcase_25 AC 2,244 ms
100,108 KB
権限があれば一括ダウンロードができます

ソースコード

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