結果
| 問題 | No.2 素因数ゲーム | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2019-10-22 12:54:20 | 
| 言語 | Lua (LuaJit 2.1.1734355927) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,539 bytes | 
| コンパイル時間 | 395 ms | 
| コンパイル使用メモリ | 6,944 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-02 18:03:36 | 
| 合計ジャッジ時間 | 1,143 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 31 | 
ソースコード
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
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x / dv
      while(x % dv == 0) do
        x = x / dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if(primepos == prime_num) then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if(x ~= 1) then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end
local function getxor(x, y)
  local ret = 0
  local mul = 1
  while(0 < x or 0 < y) do
    if((x % 2) + (y % 2) == 1) then
      ret = ret + mul
    end
    x, y, mul = mfl(x / 2), mfl(y / 2), mul * 2
  end
  return ret
end
local n = io.read("*n")
local primes = getprimes(mce(msq(n)))
local divp = getdivisorparts(n, primes)
local z = 0
for i = 1, #divp do
  local c = divp[i].cnt
  z = getxor(z, c)
end
print(z == 0 and "Bob" or "Alice")
            
            
            
        