結果

問題 No.1140 EXPotentiaLLL!
ユーザー phsplsphspls
提出日時 2020-07-31 23:01:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 143,720 KB
実行使用メモリ 6,796 KB
最終ジャッジ日時 2023-09-21 01:59:32
合計ジャッジ時間 9,691 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 811 ms
6,796 KB
testcase_01 AC 783 ms
6,728 KB
testcase_02 AC 804 ms
6,724 KB
testcase_03 AC 646 ms
6,744 KB
testcase_04 AC 504 ms
6,760 KB
testcase_05 AC 798 ms
6,724 KB
testcase_06 AC 739 ms
6,740 KB
testcase_07 AC 824 ms
6,740 KB
testcase_08 AC 27 ms
6,736 KB
testcase_09 AC 28 ms
6,732 KB
testcase_10 AC 28 ms
6,696 KB
testcase_11 AC 29 ms
6,760 KB
testcase_12 AC 28 ms
6,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn get_primes() -> Vec<bool> {
    const LIM: usize = 5 * 1e6 as usize;
    let mut flgs = vec![true; LIM+1];
    flgs[0] = false;
    flgs[1] = false;
    let limit = (LIM as f64).sqrt().ceil() as usize;
    for i in 0..=limit {
        if !flgs[i] { continue; }
        for j in i..=LIM/i {
            flgs[i*j] = false;
        }
    }
    flgs
}

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: usize = t.trim().parse().unwrap();
    let primes = get_primes();
    for _ in 0..t {
        let mut ap = String::new();
        std::io::stdin().read_line(&mut ap).ok();
        let ap: Vec<usize> = ap.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = ap[0];
        let p = ap[1];
        if !primes[p] {
            println!("-1");
        } else {
            println!("{}", if a % p == 0 { 0 } else { 1 });
        }
    }
}
0