結果

問題 No.368 LCM of K-products
ユーザー 👑 obakyanobakyan
提出日時 2020-05-05 09:10:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,729 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 08:07:55
合計ジャッジ時間 2,047 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,380 KB
testcase_01 AC 9 ms
4,376 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,384 KB
testcase_05 AC 17 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 6 ms
4,384 KB
testcase_23 AC 2 ms
4,388 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs

local mod = 1000000007
local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while primepos <= prime_num and dv <= lim do
    if x % dv == 0 then
      local cnt = 1
      x = x / dv
      while x % dv == 0 do
        x = x / dv
        cnt = cnt + 1
      end
      tmp[dv] = cnt
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    tmp[x] = 1
  end
  return tmp
end

local primes = getprimes(33333)
local t = {}
local n, k = io.read("*n", "*n")
for i = 1, n do
  local a = io.read("*n")
  local dvp = getdivisorparts(a, primes)
  for v, c in pairs(dvp) do
    if not t[v] then
      t[v] = {}
    end
    table.insert(t[v], c)
  end
end
local ret = 1
for p, tbl in pairs(t) do
  local lim = #tbl
  if k < #tbl then
    table.sort(tbl, function(a, b) return a > b end)
    lim = k
  end
  for i = 1, lim do
    local v = tbl[i]
    for j = 1, v do
      ret = bmul(ret, p)
    end
  end
end
print(ret)
0