結果

問題 No.2725 Coprime Game 2
ユーザー koba-e964koba-e964
提出日時 2024-04-13 11:06:00
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,456 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 159,240 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-13 11:06:03
合計ジャッジ時間 3,040 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 160 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::cmp::*`
 --> main.rs:1:5
  |
1 | use std::cmp::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: function `gcd` is never used
  --> main.rs:27:4
   |
27 | fn gcd(x: usize, y: usize) -> usize {
   |    ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: 2 warnings emitted

ソースコード

diff #

use std::cmp::*;
use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn gcd(x: usize, y: usize) -> usize {
    if x < y { gcd(y, x) } else if y == 0 { x } else { gcd(y, x % y) }
}

// https://yukicoder.me/problems/no/2725 (3)
// 実験の結果、n = 2, 6, 18, 30, 42, 54, ... で後手必勝、それ以外で先手必勝であることがわかる。
// これは n = 2, 6 + 12i とみなすことができる。
// 6+12i が後手必勝なのは、先手は初手で奇数に行くしかなく、後手は 4 に行けば勝てるためである。
// 他の場合で先手必勝なのもほとんど明らか。(12|N なら初手 5、2|N and not(3|N) なら初手 3 など)
fn main() {
    let t: i32 = get();
    for _ in 0..t {
        let n: i64 = get();
        println!("{}", if n == 2 || n % 12 == 6 {
            "P"
        } else {
            "K"
        });
    }
}
0