結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー 👑 obakyanobakyan
提出日時 2021-07-21 22:26:43
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,478 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2023-09-24 18:35:43
合計ジャッジ時間 17,877 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
6,572 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 12 ms
6,660 KB
testcase_29 AC 12 ms
6,680 KB
testcase_30 AC 12 ms
6,748 KB
testcase_31 AC 12 ms
6,508 KB
testcase_32 AC 12 ms
6,660 KB
testcase_33 AC 12 ms
6,520 KB
testcase_34 AC 12 ms
6,592 KB
testcase_35 WA -
testcase_36 AC 12 ms
6,504 KB
testcase_37 AC 12 ms
6,588 KB
testcase_38 AC 12 ms
6,568 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
      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(400000)
local q = io.read("*n")
for iq = 1, q do
  local x = io.read("*n")
  local dvp = getdivisorparts(x, primes)
  local v = false
  for i = 1, #primes do
    local p = primes[i]
    if dvp[p] then
      local z = 1
      for j = 0, dvp[p] do
        z = z * p
      end
      if v then v = mmi(v, z) else v = z end
    else
      if v then v = mmi(v, p) else v = p end
      break
    end
  end
  local z = 1LL * v
  z = tostring(z * x):gsub("LL", "")
  print(z)
end
0