結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー 👑 obakyanobakyan
提出日時 2021-07-21 23:25:54
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 1,941 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 6,704 KB
最終ジャッジ日時 2023-09-24 19:55:26
合計ジャッジ時間 37,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,548 ms
6,604 KB
testcase_01 AC 1,982 ms
6,644 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 233 ms
6,676 KB
testcase_11 AC 1,907 ms
6,704 KB
testcase_12 AC 1,461 ms
6,584 KB
testcase_13 AC 1,435 ms
6,500 KB
testcase_14 AC 1,466 ms
6,600 KB
testcase_15 AC 1,470 ms
6,528 KB
testcase_16 AC 1,457 ms
6,592 KB
testcase_17 AC 1,449 ms
6,492 KB
testcase_18 AC 1,424 ms
6,500 KB
testcase_19 AC 18 ms
6,520 KB
testcase_20 AC 17 ms
6,596 KB
testcase_21 AC 22 ms
6,560 KB
testcase_22 AC 16 ms
6,560 KB
testcase_23 AC 18 ms
6,596 KB
testcase_24 AC 18 ms
6,556 KB
testcase_25 AC 18 ms
6,588 KB
testcase_26 AC 17 ms
6,560 KB
testcase_27 AC 17 ms
6,592 KB
testcase_28 AC 11 ms
6,588 KB
testcase_29 AC 11 ms
6,588 KB
testcase_30 AC 12 ms
6,496 KB
testcase_31 AC 11 ms
6,604 KB
testcase_32 AC 11 ms
6,560 KB
testcase_33 AC 11 ms
6,624 KB
testcase_34 AC 11 ms
6,556 KB
testcase_35 AC 12 ms
6,556 KB
testcase_36 AC 11 ms
6,612 KB
testcase_37 AC 12 ms
6,620 KB
testcase_38 AC 12 ms
6,612 KB
権限があれば一括ダウンロードができます

ソースコード

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 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
      -- (z + 1) * 2 - 1
      for j = 1, z - 1 do
        v = v * p
      end
      for j = z, 2 * z + 1 do
        v = v * p
        if rem % (j + 1) == 0 then
          DIG(i + 1, mfl(rem / (j + 1)), v)
        end
      end
    end
  end
  if 1 < x then
    DIG(1, tot * 2, 1)
  end
  print(ans)
end
0