結果

問題 No.1140 EXPotentiaLLL!
ユーザー 👑 obakyanobakyan
提出日時 2020-08-13 22:45:06
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 01:54:23
合計ジャッジ時間 7,171 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 725 ms
5,248 KB
testcase_01 AC 332 ms
5,376 KB
testcase_02 AC 745 ms
5,376 KB
testcase_03 AC 424 ms
5,376 KB
testcase_04 AC 329 ms
5,376 KB
testcase_05 AC 515 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 916 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

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()
  a, p = s:match("(%d+) (%d+)")
  p = tonumber(p)
  a = lltonumber(a)
  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
0