結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー 👑 obakyanobakyan
提出日時 2021-08-27 21:27:37
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 32 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 37,504 KB
最終ジャッジ日時 2024-05-01 01:37:16
合計ジャッジ時間 3,837 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
37,312 KB
testcase_01 AC 129 ms
37,312 KB
testcase_02 AC 134 ms
37,428 KB
testcase_03 AC 113 ms
37,496 KB
testcase_04 AC 122 ms
37,280 KB
testcase_05 AC 125 ms
37,424 KB
testcase_06 AC 123 ms
37,480 KB
testcase_07 AC 129 ms
37,340 KB
testcase_08 AC 118 ms
37,504 KB
testcase_09 AC 122 ms
37,308 KB
testcase_10 AC 118 ms
37,372 KB
testcase_11 AC 121 ms
37,416 KB
testcase_12 AC 115 ms
37,304 KB
testcase_13 AC 116 ms
37,488 KB
testcase_14 AC 119 ms
37,340 KB
testcase_15 AC 116 ms
37,420 KB
testcase_16 AC 120 ms
37,472 KB
testcase_17 AC 123 ms
37,420 KB
testcase_18 AC 121 ms
37,428 KB
testcase_19 AC 103 ms
37,460 KB
testcase_20 AC 113 ms
37,480 KB
testcase_21 AC 106 ms
37,420 KB
testcase_22 AC 124 ms
37,488 KB
testcase_23 AC 131 ms
37,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs

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(3000000)
local l, r = io.read("*n", "*n")
--[[
(a + b) * (b - a + 1) / 2
b - a + 1 = 2
a + 1 = b
]]
local c = 0
for i = 1, #primes do
  local p = primes[i]
  if l <= p and p <= r then c = c + 1 end
  if 1 < i then
    local hp = mfl(p / 2)
    if l <= hp and hp + 1 <= r then
      c = c + 1
    end
  end
end
print(c)
0