結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
👑 |
提出日時 | 2020-08-13 22:49:21 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 963 ms / 2,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 33 ms |
コンパイル使用メモリ | 6,688 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-09 19:36:14 |
合計ジャッジ時間 | 7,203 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
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