結果
問題 | No.1747 Many Formulae 2 |
ユーザー |
👑 |
提出日時 | 2022-01-22 18:48:00 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,107 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 7,076 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-11-27 18:38:47 |
合計ジャッジ時間 | 1,498 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
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)