結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー koba-e964koba-e964
提出日時 2021-08-27 21:30:44
言語 Rust
(1.77.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,802 bytes
コンパイル時間 4,778 ms
コンパイル使用メモリ 152,460 KB
実行使用メモリ 17,632 KB
最終ジャッジ日時 2023-08-13 08:01:38
合計ジャッジ時間 6,898 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
17,576 KB
testcase_01 AC 37 ms
17,560 KB
testcase_02 AC 56 ms
17,572 KB
testcase_03 AC 56 ms
17,572 KB
testcase_04 AC 38 ms
17,496 KB
testcase_05 AC 36 ms
17,572 KB
testcase_06 AC 40 ms
17,632 KB
testcase_07 AC 42 ms
17,572 KB
testcase_08 AC 42 ms
17,588 KB
testcase_09 AC 37 ms
17,524 KB
testcase_10 AC 34 ms
17,508 KB
testcase_11 AC 41 ms
17,576 KB
testcase_12 AC 46 ms
17,568 KB
testcase_13 AC 38 ms
17,568 KB
testcase_14 AC 51 ms
17,564 KB
testcase_15 AC 42 ms
17,568 KB
testcase_16 AC 39 ms
17,588 KB
testcase_17 AC 36 ms
17,504 KB
testcase_18 AC 38 ms
17,568 KB
testcase_19 AC 37 ms
17,492 KB
testcase_20 AC 38 ms
17,572 KB
testcase_21 AC 43 ms
17,560 KB
testcase_22 AC 37 ms
17,628 KB
testcase_23 AC 50 ms
17,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input!(l: usize, r: usize);
    const W: usize = 2_000_010;
    let mut fac = vec![0; W];
    for i in 2..W {
        if fac[i] != 0 {
            continue;
        }
        fac[i] = i;
        for j in 2..(W - 1) / i + 1 {
            fac[i * j] = i;
        }
    }
    let mut ans = 0;
    for i in l..r + 1 {
        if fac[i] == i {
            ans += 1;
        }
        if i < r && fac[2 * i + 1] == 2 * i + 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}
0