結果
| 問題 |
No.1140 EXPotentiaLLL!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-13 22:45:06 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 912 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 5,504 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 19:36:04 |
| 合計ジャッジ時間 | 7,803 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 WA * 3 |
ソースコード
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