結果
問題 |
No.144 エラトステネスのざる
|
ユーザー |
👑 |
提出日時 | 2019-04-29 11:26:27 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 1,130 ms / 2,000 ms |
コード長 | 879 bytes |
コンパイル時間 | 251 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 02:55:01 |
合計ジャッジ時間 | 8,757 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
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 lim = math.ceil(math.sqrt(x)) 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))