結果

問題 No.889 素数!
ユーザー tonyu0
提出日時 2020-03-17 20:17:28
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 11,558 ms
コンパイル使用メモリ 378,812 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-30 22:53:23
合計ジャッジ時間 13,541 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut is_prime: Vec<usize> = vec![1; 300030];
    is_prime[0] = 0;
    is_prime[1] = 0;
    for i in 2..65 {is_prime[i*i] = 2; is_prime[i*i*i] = 3; if is_prime[i] == 1 {let mut j = i * 2;while j <= n {if is_prime[j]==1{is_prime[j] = 0;}j += i;}}}

    match is_prime[n] {
        1 => println!("Sosu!"),
        2 => println!("Heihosu!"),
        3 => println!("Ripposu!"),
        _ => {
            if n == 6 || n == 28 {
                println!("Kanzensu!");
            } else {
                println!("{}", n);
            }
        }
    }
}
0