結果
問題 | No.144 エラトステネスのざる |
ユーザー |
👑 |
提出日時 | 2019-04-29 11:05:27 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 1,966 ms / 2,000 ms |
コード長 | 659 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-24 02:17:07 |
合計ジャッジ時間 | 13,160 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
local n, p = io.read("*n", "*n")-- Lua 5.1local function getyakusuu(x)local tmp = {}local lim = math.ceil(math.sqrt(x))local dv = 2while(1 < x and dv <= lim) doif(x % dv == 0) thentmp[dv] = 1x = x / dvwhile(x % dv == 0) dox = x / dvtmp[dv] = tmp[dv] + 1endenddv = dv + (dv == 2 and 1 or 2)endif(x ~= 1) then tmp[x] = 1 endlocal cnt = 1for k, v in pairs(tmp) docnt = cnt * (v + 1)endreturn cntendlocal tot = 0for i = 2, n dolocal z = getyakusuu(i) - 2if(z == 0) then tot = tot + 1else tot = tot + (1 - p)^z endendprint(string.format("%.8f", tot))