結果

問題 No.144 エラトステネスのざる
ユーザー keidenkeiden
提出日時 2024-09-18 09:35:46
言語 Rust
(1.77.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 13,351 ms
コンパイル使用メモリ 379,024 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-09-18 09:36:01
合計ジャッジ時間 14,643 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io;
use std::io::prelude::*;

fn main() -> () {
    let stdin = io::read_to_string(io::stdin()).unwrap();
    let mut stdin = stdin.split_ascii_whitespace();
    let stdout = io::stdout();
    let mut stdout = io::BufWriter::new(stdout.lock());

    let n: usize = stdin.next().unwrap().parse::<usize>().unwrap();
    let p: f64 = stdin.next().unwrap().parse::<f64>().unwrap();
    let mut d = vec![0; n + 1];
    for i in 2..=n {
        let mut j = 2 * i;
        while j <= n {
            d[j] += 1;
            j += i;
        }
    }
    let res = (|| {
        let mut e = 0.0;
        for i in 2..=n {
            e += (1.0 - p).powi(d[i]);
        }
        e
    })();
    writeln!(stdout, "{}", res).unwrap_or(());
}
0