結果

問題 No.1164 GCD Products hard
ユーザー 👑 obakyanobakyan
提出日時 2021-08-10 11:15:47
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,715 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 141,788 KB
最終ジャッジ日時 2023-10-23 18:42:21
合計ジャッジ時間 28,615 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 AC 2 ms
4,372 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 1 ms
4,372 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,372 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 mod6 = 1000000006

local function bmul6(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14123 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod6
end

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

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 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 a, b, n = io.read("*n", "*n", "*n")
local ans = 1
local primes = getprimes(b)
for i = 1, #primes do
  local p = primes[i]
  while true do
    local p2 = p * p
    local c1 = mfl(b / p) - mfl((a - 1) / p)
    local c2 = mfl(b / p2) - mfl((a - 1) / p2)
    local v = (modpow6(c1, n) - modpow6(c2, n) + mod6) % mod6
    ans = bmul(ans, modpow(p, v))
    p = p2
    if b < p then break end
  end
end
print(ans)
0