結果

問題 No.2721 "Don't say N" Game
ユーザー atcoder8atcoder8
提出日時 2024-04-12 21:25:56
言語 Rust
(1.77.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 6,823 ms
コンパイル使用メモリ 174,064 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-12 21:26:03
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

fn main() {
    input! {
        t: usize,
        nn: [usize; t],
    }

    for n in nn {
        println!(
            "{}",
            if find_divisors(n).len() % 2 == 0 {
                'K'
            } else {
                'P'
            }
        );
    }
}

/// Creates a sequence consisting of the divisors of `n`.
pub fn find_divisors(n: usize) -> Vec<usize> {
    assert_ne!(n, 0, "`n` must be at least 1.");

    let mut divisors = vec![];

    for i in (1..).take_while(|&i| i <= n / i) {
        if n % i == 0 {
            divisors.push(i);

            if n / i != i {
                divisors.push(n / i);
            }
        }
    }

    divisors.sort_unstable();

    divisors
}
0