結果

問題 No.2751 429-like Number
ユーザー 👑 obakyan
提出日時 2024-08-15 22:26:34
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 547 ms / 4,000 ms
コード長 1,186 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-15 22:26:38
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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 ans = 0
  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
      ans = ans + 1
      x = mfl(x / dv)
      while x % dv == 0 do
        x = mfl(x / dv)
        ans = ans + 1
      end
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    ans = ans + 1
  end
  return ans
end
local primes = getprimes(100000)
local q = io.read("*n")
for iq = 1, q do
  local a = io.read("*n")
  local v = getdivisorparts(a, primes)
  if v == 3 then
    print("Yes")
  else
    print("No")
  end
end
0