結果
| 問題 |
No.1529 Constant Lcm
|
| コンテスト | |
| ユーザー |
wolgnik
|
| 提出日時 | 2021-06-04 20:42:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,146 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 162,688 KB |
| 最終ジャッジ日時 | 2024-11-19 10:07:22 |
| 合計ジャッジ時間 | 62,627 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 TLE * 15 |
ソースコード
import sys
input = sys.stdin.readline
N = int(input())
mod = 998244353
class sieve:
def __init__(self, n):
self.n = n
self.sv = [1] * (n + 1)
self.sv[0] = 0
self.sv[1] = 0
for i in range(2, n + 1):
if self.sv[i]:
for j in range(i * 2, n + 1, i):
self.sv[j] = 0
def isprime(self, x):
if x > self.n:
return False
return self.sv[x] == 1
def factorize(self, x):
res = []
for i in range(2, int(x ** 0.5) + 1):
if self.sv[i]:
while x % i == 0:
x //= i
res.append(i)
if x != 1:
res.append(x)
return res
def modlcm(self, a, mod):
res = [0] * (self.n + 1)
ex = set()
for i in range(len(a)):
f = self.factorize(a[i])
for j in f:
if j > self.n:
ex.add(j)
continue
res[j] = max(f.count(j), res[j])
rres = 1
for i in range(self.n + 1):
if res[i] != 0:
rres *= pow(i, res[i], mod)
rres %= mod
for i in ex:
rres *= i
rres %= mod
return rres
sv = sieve(N)
a = [x * (N - x) for x in range(1, N // 2 + 1)]
print(sv.modlcm(a, mod))
wolgnik