結果

問題 No.726 Tree Game
ユーザー kk
提出日時 2021-02-16 19:20:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 2,667 ms
コンパイル使用メモリ 192,600 KB
最終ジャッジ日時 2025-01-18 21:32:53
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

bool isprime(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;

  for (long long i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return false;

  return true;
}

bool check(long long y, long long x) {
  if (isprime(y) && isprime(x))
    return false;

  long long xt = x, yt = y;
  if (isprime(y)) {
    if (isprime(y+1))
      return false;
    ++yt;
  }
  if (isprime(x)) {
    if (isprime(x+1))
      return false;
    ++xt;
  }

  while (!isprime(xt+1)) xt++;
  while (!isprime(yt+1)) yt++;
  if (((xt - x) + (yt - y)) % 2)
    return true;
  else
    return false;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long long x, y;
  cin >> y >> x;

  if (check(y, x))
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  
  return 0;
}
0