結果

問題 No.1140 EXPotentiaLLL!
ユーザー ikd
提出日時 2020-07-31 22:20:24
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1,100 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 13,260 ms
コンパイル使用メモリ 378,816 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-07-06 18:40:31
合計ジャッジ時間 21,045 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let token: String = std::io::stdin()
        .bytes()
        .map(|c| c.ok().unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n = 5 * 1000000 + 1;
    let mut is_prime = vec![true; n];
    is_prime[1] = false;
    for i in 2..n {
        if i * i >= n {
            break;
        }
        if is_prime[i] {
            let mut j = i * 2;
            while j < n {
                is_prime[j] = false;
                j += i;
            }
        }
    }

    let t: usize = read();
    for _ in 0..t {
        let a: i64 = read();
        let p: i64 = read();
        let ans = if is_prime[p as usize] {
            if a % p == 0 {
                0
            } else {
                1
            }
        } else {
            -1
        };
        println!("{}", ans);
    }
}
0