結果

問題 No.726 Tree Game
ユーザー k
提出日時 2021-02-16 19:20:27
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 64µs
コード長 923 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,461 ms
コンパイル使用メモリ 214,016 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-03 10:40:44
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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