結果
| 問題 |
No.826 連絡網
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-05-03 21:48:48 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 977 bytes |
| コンパイル時間 | 329 ms |
| コンパイル使用メモリ | 6,948 KB |
| 実行使用メモリ | 11,872 KB |
| 最終ジャッジ日時 | 2024-12-31 17:47:11 |
| 合計ジャッジ時間 | 1,634 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 30 |
ソースコード
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 = math.floor(x / i)
for j = 2, lim do
allnums[j * i] = false
end
end
end
return primes
end
local n, p = io.read("*n", "*n")
local primes = getprimes(n)
if(p == 1) then
print(1)
elseif(p * 2 <= n) then
local ret = n - 1
local lim = math.floor(n / 2)
for i = 1, #primes do
if(primes[i] ~= p and lim < primes[i]) then
ret = ret - 1
break
end
end
print(ret)
else
local isp = false
for i = 1, #primes do
if(primes[i] == p) then
isp = true
print(1)
break
end
end
if(not isp) then
local ret = n - 1
local lim = math.floor(n / 2)
for i = 1, #primes do
if(primes[i] ~= p and lim < primes[i]) then
ret = ret - 1
break
end
end
print(ret)
end
end