結果

問題 No.7 プライムナンバーゲーム
ユーザー hiromi-mihiromi-mi
提出日時 2018-12-31 19:28:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 75,312 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 00:14:21
合計ジャッジ時間 1,280 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <numeric>
//#include <tuple>
#include <cstdio>

using namespace std;

typedef long long ll;


#define rep(i,b) for(ll i=0;i<(b);++i)
#define rep1(i,b) for(ll i=1;i<=(b);++i)
#define vec vector
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int N;

vector<int> genprime(int n) {
   vector<int> prime;
   prime.push_back(2);
   for (int i=1;2*i+1<=n;i++) {
      int k = 2*i+1;
      for (int j=0;j<prime.size();j++) {
         if (sqrt(k)+1 < prime[j]) {
            break;
         }
         if ( k % prime[j] == 0) {
            goto end;
         }
      }
      prime.push_back(k);
      end:
      continue;
   }
   reverse(prime.begin(), prime.end());
   return prime;
}

int main() {
   cin >> N;
   int point = N;
   vector<int> prime;
   int theprime;
   while (1) {
      prime = genprime(point);
      theprime = 0;
      rep(i, prime.size()) {
         theprime = prime[i];
         if (point - prime[i] >= 2) {
            break;
         }
      }
      point -= theprime;
      if (point <= 1) {
         cout << "Lose" << endl;
         return 0;
      }

      prime = genprime(point);
      theprime = 0;
      rep(i, prime.size()) {
         theprime = prime[i];
         if (point - prime[i] >= 2) {
            break;
         }
      }
      point -= theprime;
      if (point <= 1) {
         cout << "Win" << endl;
         return 0;
      }
   }
}
0