結果

問題 No.1396 Giri
ユーザー HAPPAHAPPA
提出日時 2021-02-14 23:26:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 640 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 107,860 KB
最終ジャッジ日時 2023-09-29 17:24:05
合計ジャッジ時間 9,757 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,548 KB
testcase_01 AC 93 ms
71,432 KB
testcase_02 AC 640 ms
107,652 KB
testcase_03 AC 101 ms
71,844 KB
testcase_04 AC 100 ms
71,736 KB
testcase_05 AC 632 ms
107,720 KB
testcase_06 AC 95 ms
71,308 KB
testcase_07 AC 93 ms
71,692 KB
testcase_08 AC 94 ms
71,680 KB
testcase_09 AC 96 ms
71,632 KB
testcase_10 AC 95 ms
71,688 KB
testcase_11 AC 94 ms
71,516 KB
testcase_12 AC 95 ms
71,496 KB
testcase_13 AC 96 ms
71,332 KB
testcase_14 AC 93 ms
71,848 KB
testcase_15 AC 94 ms
71,444 KB
testcase_16 AC 113 ms
77,912 KB
testcase_17 AC 122 ms
78,424 KB
testcase_18 AC 151 ms
79,840 KB
testcase_19 AC 366 ms
92,756 KB
testcase_20 AC 476 ms
100,024 KB
testcase_21 AC 575 ms
104,660 KB
testcase_22 AC 632 ms
107,568 KB
testcase_23 AC 615 ms
107,860 KB
testcase_24 AC 617 ms
107,704 KB
testcase_25 AC 625 ms
107,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 998244353


class Eratosthenes:
    def __init__(self, n):
        self.n = n
        self.min_factor = [-1] * (n + 1)
        self.min_factor[0], self.min_factor[1] = 0, 1
        self.primes = []
        self.get_primes()

    def get_primes(self):
        is_prime = [True] * (self.n + 1)
        is_prime[0] = is_prime[1] = False
        for i in range(2, self.n + 1):
            if not is_prime[i]:
                continue
            self.primes.append(i)
            self.min_factor[i] = i
            for j in range(i * 2, self.n + 1, i):
                is_prime[j] = False
                if self.min_factor[j] == -1:
                    self.min_factor[j] = i

    def return_primes(self):
        return self.primes

    def prime_factorization(self, n):
        res = []
        while n != 1:
            prime = self.min_factor[n]
            exp = 0
            while self.min_factor[n] == prime:
                exp += 1
                n //= prime
            res.append((prime, exp))
        return res


def resolve():
    n = int(input())

    er = Eratosthenes(n)
    tr = er.primes[-1]
    pf = defaultdict(int)
    for i in range(1, n + 1):
        if i == tr:
            continue
        for p, ex in er.prime_factorization(i):
            pf[p] = max(pf[p], ex)

    res = 1
    for k, v in pf.items():
        res *= pow(k, v, mod)
        res %= mod
    print(res)


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