結果

問題 No.1529 Constant Lcm
ユーザー ygd.ygd.
提出日時 2021-06-06 13:10:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 306,872 KB
最終ジャッジ日時 2024-05-02 07:38:14
合計ジャッジ時間 26,834 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,272 KB
testcase_01 AC 68 ms
68,608 KB
testcase_02 AC 42 ms
53,632 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 42 ms
54,144 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 798 ms
153,324 KB
testcase_12 AC 98 ms
79,488 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 841 ms
170,664 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2,599 ms
304,764 KB
testcase_21 AC 2,604 ms
305,368 KB
testcase_22 AC 2,603 ms
304,088 KB
testcase_23 TLE -
testcase_24 AC 2,610 ms
303,800 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict 

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2') #nが1の場合はエラーを返す。
    prime = [2]
    if n == 2:
        return prime
    limit = int(n**0.5) #ルートn以上で割れることはない
    data = [i + 1 for i in range(2, n, 2)] #最初から3スタートの奇数にしておく
    while True:
        p = data[0]
        if limit < p: #ここでイコールが入るとlimitが素数の時にlimit^2が残ってダメ。
            return prime + data
        prime.append(p) #ここで一番最初に取り出した素数を加える
        data = [e for e in data if e % p != 0] #残りでその素数で割れない数字を取得。

def main():
    n = int(input()); MOD = 998244353
    Prime = get_sieve_of_eratosthenes(n)
    m = n//2
    mx = m*2 #数列の長さ*2
    L = [defaultdict(int) for _ in range(m)]
    ans_dic = defaultdict(int)
    #print(Prime)
    for x in Prime:
        val = x
        #cnt = 1
        while val < n:
            idx = val
            while idx < mx:
                if idx <= m:
                    loc = idx - 1
                else:
                    loc = mx - idx
                #print(idx,loc)
                L[loc][x] += 1
                ans_dic[x] = max(ans_dic[x], L[loc][x])
                idx += val
            #print(L)
            val *= x
            #cnt += 1
    #print(ans_dic)
    ans = 1
    for x in ans_dic.keys():
        val = ans_dic[x]
        ans *= pow(x,val,MOD)
        ans %= MOD
    print(ans)    

if __name__ == '__main__':
    main()
0