結果
問題 |
No.726 Tree Game
|
ユーザー |
![]() |
提出日時 | 2020-03-28 03:12:05 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 1,618 ms |
コンパイル使用メモリ | 174,756 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 06:01:50 |
合計ジャッジ時間 | 1,941 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
import std; bool isPrime(int n) { if (n == 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } int nextPrimeDistance(int n) { if (n == 1 || n == 2) return 0; // if (n % 2 == 0) return isPrime(n+1) ? 0 : 2; if (n % 2 == 0) return 0; return 1; } string calc(int y, int x) { if (isPrime(y) && isPrime(x)) return "Second"; if (x == 2 || y == 2) return "Second"; int d = nextPrimeDistance(y) + nextPrimeDistance(x); if (d % 2 == 1) return "First"; else return "Second"; } void main() { int y, x; scan(y, x); writeln(calc(y, x)); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int;