結果

問題 No.144 エラトステネスのざる
ユーザー 👑 obakyanobakyan
提出日時 2019-04-29 11:25:03
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 843 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 5,276 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-08-25 17:26:03
合計ジャッジ時間 4,039 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

local n, p = io.read("*n", "*n")

local function getyakusuu(x)
  local tmp = {}
  local lim = math.ceil(math.sqrt(x))
  local dv = 2
  local rt, rti = {4, 2, 4, 2, 4, 6, 2, 6}, 1
  while(1 < x and dv <= lim) do
    if(x % dv == 0) then
      tmp[dv] = 1
      x = x / dv
      while(x % dv == 0) do
        x = x / dv
        tmp[dv] = tmp[dv] + 1
      end
    end
    if(dv == 2) then dv = 3
    elseif(dv == 3) then dv = 5
    elseif(dv == 5) then dv = 7
    else
      dv, rti = dv + rt[rti], rti + 1
      if(rti == 9) then rti = 1 end
    end
  end
  if(x ~= 1) then tmp[x] = 1 end
  local cnt = 1
  for k, v in pairs(tmp) do
    cnt = cnt * (v + 1)
  end
  return cnt
end

local tot = 0
for i = 2, n do
  local z = getyakusuu(i) - 2
  if(z == 0) then tot = tot + 1
  else tot = tot + (1 - p)^z end
end
print(string.format("%.8f", tot))
0