結果

問題 No.7 プライムナンバーゲーム
ユーザー SakaTakuSakaTaku
提出日時 2020-09-05 18:45:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,306 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 170,068 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 04:58:56
合計ジャッジ時間 2,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
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 result[10001];
int main() {
   result[0]=result[1]=true;
   int N;cin>>N;
   Sieve prime(N);
   for (int i = 2; i <= N; i++){
      bool res=true;
      for (auto &&p : prime.primes){
         if(p>i)break;
         res&=result[i-p];
      }
      result[i]=!res;
   }
   cout<<(result[N]?"Win":"Lose")<<endl;
}
0