結果

問題 No.144 エラトステネスのざる
ユーザー 👑 obakyanobakyan
提出日時 2019-04-29 11:05:27
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,916 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 17:00:47
合計ジャッジ時間 14,518 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_13 AC 1,897 ms
4,376 KB
testcase_14 AC 1,916 ms
4,380 KB
testcase_15 AC 1,912 ms
4,380 KB
testcase_16 AC 1,898 ms
4,380 KB
testcase_17 AC 1,906 ms
4,376 KB
testcase_18 AC 1,881 ms
4,376 KB
testcase_19 AC 1,878 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n, p = io.read("*n", "*n")
-- Lua 5.1
local function getyakusuu(x)
  local tmp = {}
  local lim = math.ceil(math.sqrt(x))
  local dv = 2
  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
    dv = dv + (dv == 2 and 1 or 2)
  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