結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
|
提出日時 | 2024-09-27 18:20:29 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 5,000 ms |
コード長 | 918 bytes |
コンパイル時間 | 4,491 ms |
コンパイル使用メモリ | 318,536 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-27 18:20:35 |
合計ジャッジ時間 | 5,187 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using i64 = long long; std::vector<int> p; int fact = []() { constexpr int n = 1e5; std::vector<int> st(n + 1, 0); st[0] = st[1] = 1; for (int i = 2; i <= n; ++i) { if (!st[i]) { p.push_back(i); } for (auto &pi : p) { if (1LL * i * pi > n) break; st[i * pi] = 1; if (i % pi == 0) break; } } return 0; }(); int main() { std::cin.tie(nullptr)->sync_with_stdio(false); i64 n; std::cin >> n; std::vector<int> dp(n + 2, 0); const int m = p.size(); dp[0] = dp[1] = 1; for (int i = 0; i <= n; ++i) { for (int j = 0; j < m; ++j) { if (i - p[j] < 0) continue; if (!dp[i - p[j]]) { dp[i] = 1; break; } } } std::cout << (dp[n] ? "Win" : "Lose") << '\n'; return 0; }