結果

問題 No.1140 EXPotentiaLLL!
ユーザー fukafukatanifukafukatani
提出日時 2020-10-09 13:27:32
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,351 bytes
コンパイル時間 4,792 ms
コンパイル使用メモリ 143,200 KB
実行使用メモリ 6,884 KB
最終ジャッジ日時 2023-09-27 12:38:59
合計ジャッジ時間 11,868 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 794 ms
6,800 KB
testcase_01 AC 778 ms
6,800 KB
testcase_02 WA -
testcase_03 AC 661 ms
6,728 KB
testcase_04 AC 511 ms
6,800 KB
testcase_05 AC 787 ms
6,832 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 35 ms
6,808 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 36 ms
6,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:21:9
   |
21 |     for i in 0..t {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `a`
  --> Main.rs:23:14
   |
23 |         let (a, p) = (v[0], v[1]);
   |              ^ help: if this is intentional, prefix it with an underscore: `_a`

warning: 2 warnings emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let t = read::<usize>();
    let is_prime = get_primes(5000001);
    for i in 0..t {
        let v = read_vec::<i64>();
        let (a, p) = (v[0], v[1]);
        if is_prime[p as usize] {
            println!("1");
        } else {
            println!("-1");
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn get_primes(n: i64) -> Vec<bool> {
    let mut is_prime = vec![true; n as usize + 1];
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        if is_prime[i as usize] {
            let mut j = 2 * i;
            while j < n {
                is_prime[j as usize] = false;
                j += i;
            }
        }
    }
    is_prime
}
0