結果

問題 No.144 エラトステネスのざる
ユーザー iwotiwot
提出日時 2020-06-23 17:16:51
言語 OCaml
(5.1.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 413 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 21,576 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-17 09:03:43
合計ジャッジ時間 1,676 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 41 ms
11,516 KB
testcase_14 AC 41 ms
11,392 KB
testcase_15 AC 40 ms
11,392 KB
testcase_16 AC 44 ms
11,392 KB
testcase_17 AC 41 ms
11,520 KB
testcase_18 AC 44 ms
11,392 KB
testcase_19 AC 41 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let solve n p =
    let p2 = 1.0 -. p in
    let s = Array.init (n+1) (fun i -> 1.0) in
    let ans = ref 0.0 in
    for i = 2 to n do
        ans :=  !ans +. s.(i);
        let j = ref (i*2) in
        while !j <= n do
            s.(!j) <- s.(!j) *. p2;
            j := !j + i;
        done
    done;
    !ans


let () = Scanf.scanf "%d %f" (fun n p ->
    let ans = solve n p in
    Printf.printf "%f\n" ans)
0