結果

問題 No.1529 Constant Lcm
ユーザー ygd.ygd.
提出日時 2021-06-06 13:17:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,800 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 285,924 KB
最終ジャッジ日時 2024-05-02 07:44:54
合計ジャッジ時間 10,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
53,888 KB
testcase_01 AC 77 ms
68,992 KB
testcase_02 AC 49 ms
53,888 KB
testcase_03 WA -
testcase_04 AC 49 ms
54,272 KB
testcase_05 AC 54 ms
53,760 KB
testcase_06 AC 50 ms
54,144 KB
testcase_07 AC 53 ms
53,760 KB
testcase_08 AC 51 ms
53,760 KB
testcase_09 WA -
testcase_10 AC 2,993 ms
285,924 KB
testcase_11 AC 1,011 ms
152,904 KB
testcase_12 AC 124 ms
79,340 KB
testcase_13 AC 2,464 ms
254,684 KB
testcase_14 AC 1,319 ms
182,372 KB
testcase_15 AC 1,478 ms
185,220 KB
testcase_16 AC 1,127 ms
169,996 KB
testcase_17 AC 599 ms
123,740 KB
testcase_18 AC 653 ms
122,044 KB
testcase_19 AC 1,459 ms
182,360 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
権限があれば一括ダウンロードができます

ソースコード

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 = n - 1 - idx
                #print(idx,loc)
                L[loc][x] += 1
                if n%2 == 0 and loc == m - 1:
                    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