結果

問題 No.1140 EXPotentiaLLL!
ユーザー tonyu0tonyu0
提出日時 2020-07-31 22:48:41
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 922 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 145,672 KB
実行使用メモリ 24,636 KB
最終ジャッジ日時 2023-09-21 01:26:41
合計ジャッジ時間 4,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
24,164 KB
testcase_01 AC 117 ms
24,604 KB
testcase_02 WA -
testcase_03 AC 90 ms
16,216 KB
testcase_04 AC 78 ms
15,904 KB
testcase_05 AC 103 ms
24,636 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 34 ms
6,780 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 34 ms
6,836 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::cmp::*`
 --> Main.rs:1:5
  |
1 | use std::cmp::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::cmp::*;
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 t: usize = itr.next().unwrap().parse().unwrap();
    const MAX: usize = 5000005;
    let mut is_prime: Vec<bool> = vec![true; MAX];
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..MAX {
        if is_prime[i] {
            let mut j = i * 2;
            while j < MAX {
                is_prime[j] = false;
                j += i;
            }
        }
    }

    let mut out = Vec::new();
    for _ in 0..t {
        let _: u64 = itr.next().unwrap().parse().unwrap();
        let p: u64 = itr.next().unwrap().parse().unwrap();

        if is_prime[p as usize] {
            writeln!(out, "1").ok();
        } else {
            writeln!(out, "-1").ok();
        }
    }
    stdout().write_all(&out).unwrap();
}
0