結果
| 問題 |
No.726 Tree Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-24 22:11:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 976 bytes |
| コンパイル時間 | 1,667 ms |
| コンパイル使用メモリ | 197,880 KB |
| 最終ジャッジ日時 | 2025-01-06 12:34:28 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 7 |
ソースコード
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> list_primes(int n) {
vector<bool> is_prime(n, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i *(ll) i < n; ++ i)
if (is_prime[i])
for (int k = 2 * i; k < n; k += i)
is_prime[k] = false;
vector<int> primes;
for (int i = 2; i < n; ++ i)
if (is_prime[i])
primes.push_back(i);
return primes;
}
bool is_prime(ll n, vector<int> const & primes) {
for (int p : primes) {
if (n < (ll)p * p) break;
if (n % p == 0) return true;
}
return false;
}
bool solve(int y, int x) {
const auto primes = list_primes(1e5);
int h = y;
int w = x;
while (not is_prime(y + h, primes)) ++ h;
while (not is_prime(x + w, primes)) ++ w;
return (h % 2) ^ (w % 2);
}
int main() {
int y, x; cin >> y >> x;
cout << (solve(y, x) ? "First" : "Second") << endl;
return 0;
}