結果

問題 No.1140 EXPotentiaLLL!
ユーザー 👑 obakyanobakyan
提出日時 2020-08-13 22:49:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 914 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 01:54:33
合計ジャッジ時間 6,845 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 721 ms
6,816 KB
testcase_01 AC 316 ms
6,940 KB
testcase_02 AC 736 ms
6,944 KB
testcase_03 AC 418 ms
6,940 KB
testcase_04 AC 327 ms
6,944 KB
testcase_05 AC 514 ms
6,944 KB
testcase_06 AC 487 ms
6,944 KB
testcase_07 AC 914 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
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 primes = getprimes(2400)

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 q = io.read("*n", "*l")
for iq = 1, q do
  local s = io.read()
  local a, p = s:match("(%d+) (%d+)")
  p = tonumber(p)
  a = lltonumber(a)
  if p == 1 then
    print(-1)
  else
    local v = true
    for i = 1, #primes do
      if p % primes[i] == 0 and p ~= primes[i] then v = false break end
    end
    if v then
      p = 1LL * p
      if a % p == 0LL then
        print(0)
      else
        print(1)
      end
    else
      print(-1)
    end
  end
end
0