結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
けーむ
|
| 提出日時 | 2020-05-11 17:46:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,626 bytes |
| コンパイル時間 | 1,776 ms |
| コンパイル使用メモリ | 177,160 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 15:14:57 |
| 合計ジャッジ時間 | 2,301 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
vector<bool> eratosthenes;
void create_eratosthenes(int n) {
eratosthenes.resize(n + 1, true);
eratosthenes[0] = eratosthenes[1] = false;
for(int i = 2; (i * i) <= n; i++) {
if (!eratosthenes[i]) {
continue;
}
for (int ii = 2; (i * ii) <= n; ii++) {
eratosthenes[i * ii] = false;
}
}
}
bool is_prime(int n) {
return eratosthenes[n];
}
ll n;
set<ll> prime;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
cin >> n;
create_eratosthenes(n);
reps(i, 1, n + 1) {
if (is_prime(i)) prime.insert(i);
}
ll turn = 0;
while(true) {
auto it = prime.lower_bound(n);
while(((*it >= n) || ((n - *it) <= 1)) && (it != prime.begin())) {
// printf("%lld->", *it);
it--;
// printf("%lld\n", *it);
}
n -= *it;
if (n <= 1) {
cout << ((turn % 2 == 1) ? "Win" : "Lose") << endl;
return 0;
}
turn++;
// printf("%lld\n", n);
}
return 0;
}
けーむ