結果

問題 No.1529 Constant Lcm
ユーザー AEnAEn
提出日時 2022-09-02 01:26:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 624 ms / 3,000 ms
コード長 938 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 92,236 KB
最終ジャッジ日時 2024-04-27 01:32:28
合計ジャッジ時間 8,582 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,320 KB
testcase_01 AC 59 ms
69,104 KB
testcase_02 AC 40 ms
54,400 KB
testcase_03 AC 40 ms
54,728 KB
testcase_04 AC 40 ms
55,372 KB
testcase_05 AC 40 ms
54,712 KB
testcase_06 AC 41 ms
55,064 KB
testcase_07 AC 45 ms
53,748 KB
testcase_08 AC 41 ms
53,876 KB
testcase_09 AC 46 ms
53,744 KB
testcase_10 AC 548 ms
90,576 KB
testcase_11 AC 247 ms
82,224 KB
testcase_12 AC 87 ms
76,824 KB
testcase_13 AC 522 ms
88,740 KB
testcase_14 AC 336 ms
84,660 KB
testcase_15 AC 345 ms
84,796 KB
testcase_16 AC 271 ms
82,824 KB
testcase_17 AC 177 ms
80,148 KB
testcase_18 AC 191 ms
80,492 KB
testcase_19 AC 348 ms
84,412 KB
testcase_20 AC 624 ms
92,084 KB
testcase_21 AC 608 ms
92,236 KB
testcase_22 AC 582 ms
92,216 KB
testcase_23 AC 597 ms
92,012 KB
testcase_24 AC 592 ms
91,948 KB
testcase_25 AC 587 ms
92,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

N = int(input())
mod = 998244353
def smallest_prime_factors(n):
    """各数の最小素因数を求める"""
    spf = [0]*(n+1)
    for i in range(n+1):
        spf[i] = i
    for i in range(2,n+1):
        if i*i>n:
            break
        if spf[i] == i:
            for j in range(i*i, n+1, i):
                if spf[j] == j:
                    spf[j] = i
    return spf

def fac(x, spf, ret) -> list:
    while x!=1:
        if spf[x] in ret:
            ret[spf[x]] += 1
        else:
            ret[spf[x]] = 1
        x //= spf[x]
    return ret

res = [0]*N
spf = smallest_prime_factors(N-1)
for i in range(N//2):
    ret = {}
    a, b = i+1, N-i-1
    ret = fac(a, spf, ret)
    ret = fac(b, spf, ret)
    for key in ret.keys():
        res[key] = max(ret[key], res[key])
ans = 1
for i in range(N):
    if res[i] != 0:
        ans *= pow(i, res[i], mod)
        ans %= mod
print(ans)
0