結果

問題 No.7 プライムナンバーゲーム
ユーザー J31831276J31831276
提出日時 2018-12-28 02:02:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 63,320 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:34:21
合計ジャッジ時間 1,311 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cmath>

#define ll long long

using namespace std;

int prime[10000];
int cnt=0;
int WL[10001]={0};

void Eratosthenes(int N){
    
    int arr[10000];

	for(int i = 0; i < N; i++) arr[i] = 1;
	
	for(int i = 2; i < sqrt(N); i++)
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
	    }

	for(int i = 2; i < N; i++)
		if(arr[i]) prime[cnt++]=i;
}

int main(){
  
   int n;
   cin>>n;
   Eratosthenes(10000);
   
   WL[0]=WL[1]=1;
   WL[2]=WL[3]=0;
   for(int i=4;i<=10000;++i){
       for(int j=0;j<cnt;++j){
           if(i-prime[j]<0) break;
           if(!WL[i-prime[j]]){
               WL[i]=1;
               break;
           }
       }
   }
    
   if(WL[n]) cout<<"Win"<<endl;
   else cout<<"Lose"<<endl;

   return 0;
}
0