結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー 👑 obakyanobakyan
提出日時 2021-07-21 23:35:34
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 2,131 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 5,292 KB
実行使用メモリ 15,268 KB
最終ジャッジ日時 2023-09-24 19:56:05
合計ジャッジ時間 6,960 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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
      x = mfl(x / dv)
      local cnt = 1
      while x % dv == 0 do
        x = mfl(x / dv)
        cnt = cnt + 1
      end
      table.insert(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
    table.insert(tmp, {x, 1})
  end
  return tmp
end

local primes = getprimes(400000)
local q = io.read("*n")
for iq = 1, q do
  local x = io.read("*n")
  local v = false
  for i = 1, #primes do
    local p = primes[i]
    if x % p ~= 0 then
      v = p
      break
    end
  end
  local ans = 1 * v
  ans = ans * x
  local dvp = getdivisorparts(x, primes)
  local tot = 1
  for i = 1, #dvp do
    tot = tot * (1 + dvp[i][2])
  end
  local box = {}
  if 1 < x then
    box[1] = dvp[#dvp][2]
    for i = 2, #dvp do
      box[i] = box[i - 1] * dvp[#dvp + 1 - i][2]
    end
  end
  local function DIG(i, rem, v)
    local p = dvp[i][1]
    local z = dvp[i][2]
    if i == #dvp then
      if z + 1 <= rem then
        for j = 1, rem - 1 do
          v = v * p
        end
        if v < ans then ans = v end
      end
    else
      for j = 1, z - 1 do
        v = v * p
      end
      for j = z, 2 * z + 1 do
        v = v * p
        local qqq = mfl(rem / (j + 1))
        if qqq < box[#dvp - i] then break end
        if rem % (j + 1) == 0 then
          DIG(i + 1, qqq, v)
        end
      end
    end
  end
  if 1 < x then
    DIG(1, tot * 2, 1)
  end
  print(ans)
end
0