結果

問題 No.1659 Product of Divisors
ユーザー 👑 obakyanobakyan
提出日時 2021-08-27 21:49:31
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 2,092 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 20,660 KB
最終ジャッジ日時 2023-08-13 08:37:47
合計ジャッジ時間 2,767 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
20,608 KB
testcase_01 AC 66 ms
20,344 KB
testcase_02 AC 64 ms
20,364 KB
testcase_03 AC 60 ms
20,592 KB
testcase_04 AC 59 ms
20,496 KB
testcase_05 AC 59 ms
20,620 KB
testcase_06 AC 61 ms
20,600 KB
testcase_07 AC 60 ms
20,324 KB
testcase_08 AC 60 ms
20,464 KB
testcase_09 AC 62 ms
20,484 KB
testcase_10 AC 65 ms
20,400 KB
testcase_11 AC 65 ms
20,452 KB
testcase_12 AC 61 ms
20,568 KB
testcase_13 AC 60 ms
20,660 KB
testcase_14 AC 61 ms
20,604 KB
testcase_15 AC 58 ms
20,496 KB
testcase_16 AC 59 ms
20,544 KB
testcase_17 AC 64 ms
20,492 KB
testcase_18 AC 61 ms
20,476 KB
testcase_19 AC 58 ms
20,560 KB
testcase_20 AC 63 ms
20,588 KB
testcase_21 AC 58 ms
20,628 KB
testcase_22 AC 60 ms
20,548 KB
testcase_23 AC 60 ms
20,488 KB
testcase_24 AC 62 ms
20,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getComb(n, k)
  local ret = 1
  local inv = 1
  for i = 1, k do
    ret = bmul(ret, (n + 1 - i) % mod)
    inv = bmul(inv, i)
  end
  return bmul(ret, modinv(inv))
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
      table.insert(tmp, 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, 1)
  end
  return tmp
end

local primes = getprimes(2000000)
local n, k = io.read("*n", "*n")
local cnts = getdivisorparts(n, primes)
local ret = 1
for i = 1, #cnts do
  local cnt = cnts[i]
  local v = 1
  for j = 1, cnt do
    v = badd(v, getComb(j + k - 1, j))
  end
  ret = bmul(ret, v)
end
print(ret)
0