結果

問題 No.1747 Many Formulae 2
ユーザー 👑 obakyanobakyan
提出日時 2022-01-22 18:47:31
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 7,092 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2023-08-18 13:19:55
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
11,276 KB
testcase_01 AC 27 ms
11,184 KB
testcase_02 AC 28 ms
11,192 KB
testcase_03 AC 28 ms
11,248 KB
testcase_04 AC 27 ms
11,248 KB
testcase_05 AC 28 ms
11,252 KB
testcase_06 AC 28 ms
11,392 KB
testcase_07 AC 28 ms
11,260 KB
testcase_08 AC 28 ms
11,280 KB
testcase_09 AC 28 ms
11,368 KB
testcase_10 AC 28 ms
11,188 KB
testcase_11 AC 28 ms
11,280 KB
testcase_12 AC 28 ms
11,280 KB
testcase_13 AC 28 ms
11,280 KB
testcase_14 AC 27 ms
11,276 KB
testcase_15 AC 30 ms
11,288 KB
testcase_16 AC 29 ms
11,196 KB
testcase_17 AC 27 ms
11,284 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
  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