結果

問題 No.7 プライムナンバーゲーム
ユーザー ScottShelbyScottShelby
提出日時 2020-08-31 21:12:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,443 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 169,948 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 04:58:48
合計ジャッジ時間 2,400 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 10 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 4 ms
6,948 KB
testcase_07 AC 4 ms
6,948 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 5 ms
6,952 KB
testcase_10 AC 2 ms
6,948 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 7 ms
6,944 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 10 ms
6,948 KB
testcase_15 AC 9 ms
6,944 KB
testcase_16 AC 8 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

bool dp[10001];
int main() {
  int n;
  cin >> n;
  Sieve s(10001);
  
  dp[0] = dp[1] = true;
  auto primes = s.primes;
  for (int i = 2; i <= n; ++i) {
    bool win = false;
    rep(j, primes.size()) {
      int prime = primes[j];
      if (prime > i) break;
      if (dp[i - prime] == false) win = true;
    }
    dp[i] = win;
  }

  string ans = (dp[n] ? "Win" : "Lose");
  cout << ans << endl;
}
0