結果

問題 No.1809 Divide NCK
ユーザー 👑 obakyanobakyan
提出日時 2022-01-15 01:04:33
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,777 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 6,812 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-30 19:58:52
合計ジャッジ時間 2,268 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
11,716 KB
testcase_01 AC 28 ms
11,752 KB
testcase_02 AC 27 ms
11,796 KB
testcase_03 AC 25 ms
11,776 KB
testcase_04 AC 24 ms
11,788 KB
testcase_05 AC 25 ms
11,780 KB
testcase_06 AC 24 ms
11,776 KB
testcase_07 AC 24 ms
11,712 KB
testcase_08 AC 25 ms
11,856 KB
testcase_09 AC 24 ms
11,904 KB
testcase_10 AC 25 ms
11,808 KB
testcase_11 AC 24 ms
11,888 KB
testcase_12 AC 24 ms
11,892 KB
testcase_13 AC 24 ms
11,868 KB
testcase_14 AC 24 ms
11,868 KB
testcase_15 AC 24 ms
11,896 KB
testcase_16 AC 25 ms
11,788 KB
testcase_17 AC 26 ms
11,852 KB
testcase_18 AC 26 ms
11,872 KB
testcase_19 AC 25 ms
11,724 KB
testcase_20 AC 25 ms
11,800 KB
testcase_21 AC 25 ms
11,896 KB
testcase_22 AC 26 ms
11,756 KB
testcase_23 AC 27 ms
11,792 KB
testcase_24 AC 26 ms
11,720 KB
testcase_25 AC 26 ms
11,756 KB
testcase_26 AC 25 ms
11,800 KB
testcase_27 AC 25 ms
11,692 KB
testcase_28 AC 25 ms
11,796 KB
testcase_29 AC 26 ms
11,716 KB
testcase_30 AC 24 ms
11,780 KB
testcase_31 AC 24 ms
11,720 KB
testcase_32 AC 24 ms
11,792 KB
testcase_33 AC 25 ms
11,836 KB
testcase_34 AC 26 ms
11,720 KB
testcase_35 AC 26 ms
11,720 KB
testcase_36 AC 26 ms
11,688 KB
testcase_37 AC 25 ms
11,716 KB
testcase_38 AC 26 ms
11,876 KB
testcase_39 AC 26 ms
11,792 KB
testcase_40 AC 25 ms
11,700 KB
testcase_41 AC 25 ms
11,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end


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 cnt = 1
      x = mfl(x / dv)
      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 n, k, m = io.read():match("(%d+) (%d+) (%d+)")
n = lltonumber(n)
k = lltonumber(k)
m = tonumber(m)
local primes = getprimes(1000 * 1000)
local dvp = getdivisorparts(m, primes)
local ret = false
for p, cnt in pairs(dvp) do
  local tmp = n
  local pl = 1LL * p
  local z = 0LL
  while 0LL < tmp do
    z = z + tmp / pl
    tmp = tmp / pl
  end
  tmp = k
  while 0LL < tmp do
    z = z - tmp / pl
    tmp = tmp / pl
  end
  tmp = n - k
  while 0LL < tmp do
    z = z - tmp / pl
    tmp = tmp / pl
  end
  z = z / (1LL * cnt)
  if not ret then
    ret = z
  elseif z < ret then
    ret = z
  end
end
ret = tostring(ret):gsub("LL", "")
print(ret)
0