結果

問題 No.1529 Constant Lcm
ユーザー wolgnikwolgnik
提出日時 2021-06-04 21:07:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 3,000 ms
コード長 1,344 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 85,100 KB
最終ジャッジ日時 2023-08-12 10:48:56
合計ジャッジ時間 5,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,096 KB
testcase_01 AC 112 ms
76,312 KB
testcase_02 AC 74 ms
71,140 KB
testcase_03 AC 75 ms
71,148 KB
testcase_04 AC 75 ms
70,980 KB
testcase_05 AC 73 ms
71,172 KB
testcase_06 AC 73 ms
71,208 KB
testcase_07 AC 73 ms
71,148 KB
testcase_08 AC 72 ms
71,128 KB
testcase_09 AC 74 ms
71,096 KB
testcase_10 AC 250 ms
84,536 KB
testcase_11 AC 167 ms
79,432 KB
testcase_12 AC 99 ms
76,808 KB
testcase_13 AC 231 ms
83,356 KB
testcase_14 AC 191 ms
81,016 KB
testcase_15 AC 181 ms
81,380 KB
testcase_16 AC 168 ms
79,796 KB
testcase_17 AC 136 ms
78,412 KB
testcase_18 AC 135 ms
78,744 KB
testcase_19 AC 191 ms
81,304 KB
testcase_20 AC 261 ms
85,044 KB
testcase_21 AC 260 ms
85,012 KB
testcase_22 AC 285 ms
84,824 KB
testcase_23 AC 253 ms
85,100 KB
testcase_24 AC 281 ms
84,856 KB
testcase_25 AC 278 ms
85,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
      fs = set(f)
      for j in fs:
        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)
res = 1
for p in range(2, N + 1):
  if sv.isprime(p) == False: continue
  c = 0
  for x in range(p, N, p):
    y = x * (N - x)
    t = 0
    while y % p == 0:
      y //= p
      t += 1
    c = max(c, t)
  res *= pow(p, c, mod)
  res %= mod
print(res)
0