結果
問題 | No.826 連絡網 |
ユーザー |
👑 |
提出日時 | 2019-05-03 21:54:08 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 951 bytes |
コンパイル時間 | 196 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 11,820 KB |
最終ジャッジ日時 | 2024-11-24 02:20:49 |
合計ジャッジ時間 | 1,547 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 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 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 end end print(ret) end end