結果

問題 No.3388 Sum of Function
コンテスト
ユーザー northward
提出日時 2025-12-04 20:54:45
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,046 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,660 ms
コンパイル使用メモリ 400,064 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-04 20:54:59
合計ジャッジ時間 13,082 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(non_snake_case, unused_must_use, unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout());
    let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock()));

    macro_rules! input {
        ($t: tt, $n: expr) => {
            (0..$n).map(|_| input!($t)).collect::<Vec<_>>()
        };
        (Chars) => {
            input!(String).chars().collect::<Vec<_>>()
        };
        (Usize1) => {
            stdin.next().unwrap().parse::<usize>().unwrap() - 1
        };
        ($t: ty) => {
            stdin.next().unwrap().parse::<$t>().unwrap()
        };
    }

    let A = input!(usize);
    let B = input!(usize);

    let f = |x| x * x * x - x * x + x + 1;

    let ans = (A..=B).filter(|&x| is_prime(x)).map(|x| f(x)).sum::<usize>();
    writeln!(buffer, "{}", ans);
}

fn is_prime(x: usize) -> bool {
    for i in 2..x {
        if x % i == 0 {
            return false;
        }
    }

    return true;
}
0