結果
問題 | No.726 Tree Game |
ユーザー |
|
提出日時 | 2022-12-08 00:17:08 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,102 bytes |
コンパイル時間 | 13,736 ms |
コンパイル使用メモリ | 378,104 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 03:19:34 |
合計ジャッジ時間 | 13,837 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
fn is_prime(val: usize) -> bool {if val == 1 { return false; }for i in 2..=(val as f64).sqrt().floor() as usize {if val % i == 0 {return false;}}true}fn main() {let mut temp = String::new();std::io::stdin().read_line(&mut temp).ok();let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let y = temp[0];let x = temp[1];let y_isprime = is_prime(y);let x_isprime = is_prime(x);if y_isprime && x_isprime {println!("Second");return;} else if x == 2 || y == 2 {println!("Second");return;}let mut nexty_prime = y;let mut nextx_prime = x;for i in y+1.. {if is_prime(i) {nexty_prime = i;break;}}for i in x+1.. {if is_prime(i) {nextx_prime = i;break;}}let diff = (nextx_prime - 1 - x) + (nexty_prime - 1 - y);if diff % 2 == 1 {println!("First");} else {println!("Second");}}