結果

問題 No.1529 Constant Lcm
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-10 13:41:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,852 ms / 3,000 ms
コード長 786 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 97,868 KB
最終ジャッジ日時 2024-04-26 20:05:44
合計ジャッジ時間 21,306 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
68,992 KB
testcase_01 AC 109 ms
84,516 KB
testcase_02 AC 72 ms
68,736 KB
testcase_03 AC 71 ms
68,480 KB
testcase_04 AC 71 ms
68,864 KB
testcase_05 AC 71 ms
69,120 KB
testcase_06 AC 71 ms
68,992 KB
testcase_07 AC 71 ms
68,864 KB
testcase_08 AC 72 ms
68,588 KB
testcase_09 AC 72 ms
68,608 KB
testcase_10 AC 1,597 ms
97,536 KB
testcase_11 AC 704 ms
88,736 KB
testcase_12 AC 148 ms
84,824 KB
testcase_13 AC 1,463 ms
94,764 KB
testcase_14 AC 860 ms
90,720 KB
testcase_15 AC 980 ms
91,976 KB
testcase_16 AC 778 ms
88,924 KB
testcase_17 AC 454 ms
87,216 KB
testcase_18 AC 466 ms
87,520 KB
testcase_19 AC 914 ms
90,960 KB
testcase_20 AC 1,852 ms
97,388 KB
testcase_21 AC 1,820 ms
97,624 KB
testcase_22 AC 1,753 ms
97,536 KB
testcase_23 AC 1,777 ms
97,868 KB
testcase_24 AC 1,774 ms
97,708 KB
testcase_25 AC 1,822 ms
97,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

N = 10**6+1
spf = [-1]*(N+1)
for i in range(N+1):
    spf[i] = i
for i in range(2, int(math.sqrt(N))+1):
    if spf[i] == i:
        for j in range(i*2, N+1, i):
            if spf[j] == j:
                spf[j] = i

from collections import defaultdict
def factorize(n):
    d = defaultdict(lambda: 0)
    if n == 1:
        d[1] = 1
        return d
    while n != 1:
        p = spf[n]
        d[p] += 1
        n //= p
    return d

n = int(input())

mod = 998244353
P = defaultdict(lambda: 0)
for i in range(1, n):
    d0 = factorize(i)
    d1 = factorize(n-i)
    for k, v in d0.items():
        P[k] = max(P[k], v+d1[k])
    for k, v in d1.items():
        P[k] = max(P[k], v+d0[k])
ans = 1
for k, v in P.items():
    ans *= pow(k, v, mod)
    ans %= mod
print(ans)
0