結果

問題 No.726 Tree Game
ユーザー kk
提出日時 2021-02-16 19:20:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 198,864 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-11 09:50:24
合計ジャッジ時間 3,222 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,356 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,368 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 2 ms
4,356 KB
testcase_24 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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