結果

問題 No.1747 Many Formulae 2
ユーザー 👑 obakyanobakyan
提出日時 2022-01-22 18:48:00
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 11,708 KB
最終ジャッジ日時 2024-05-05 18:35:46
合計ジャッジ時間 1,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,608 KB
testcase_01 AC 32 ms
11,648 KB
testcase_02 AC 32 ms
11,608 KB
testcase_03 AC 29 ms
11,608 KB
testcase_04 AC 29 ms
11,648 KB
testcase_05 AC 30 ms
11,640 KB
testcase_06 AC 29 ms
11,600 KB
testcase_07 AC 32 ms
11,648 KB
testcase_08 AC 30 ms
11,616 KB
testcase_09 AC 29 ms
11,708 KB
testcase_10 AC 29 ms
11,596 KB
testcase_11 AC 29 ms
11,648 KB
testcase_12 AC 29 ms
11,648 KB
testcase_13 AC 29 ms
11,588 KB
testcase_14 AC 29 ms
11,668 KB
testcase_15 AC 31 ms
11,552 KB
testcase_16 AC 30 ms
11,648 KB
testcase_17 AC 29 ms
11,592 KB
testcase_18 AC 30 ms
11,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs
local bls, brs = bit.lshift, bit.rshift

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(1000000)
local function isprime(x)
  if x == 1 then return false end
  for i = 1, #primes do
    if x == primes[i] then return true end
    if x % primes[i] == 0 then return false end
  end
  return true
end

local s = io.read()
local n = #s
local t = {}
for i = 1, n do
  t[i] = s:byte(i) - 48
end
local ret = 0
local tot = bls(1, n - 1)
for i = 0, tot - 1 do
  local v = 0
  local c = t[1]
  local ti = i
  for j = 2, n do
    if ti % 2 == 0 then
      c = c * 10 + t[j]
    else
      v = v + c
      c = t[j]
    end
    ti = brs(ti, 1)
  end
  v = v + c
  -- print(v)
  if isprime(v) then
    ret = ret + 1
  end
end
print(ret)
0