結果

問題 No.7 プライムナンバーゲーム
ユーザー Lay_ecLay_ec
提出日時 2014-11-12 18:00:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,183 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 79,820 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:40:20
合計ジャッジ時間 1,849 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <queue>

using namespace std; 

typedef pair<int,int> pii;
const int INF=(1<<30);


int f(long x){
	int sum=0;
	while(x){
		sum+=x%10;
		x/=10;
	}

	if(sum<10) return sum;
	else return f(sum);

}

vector<long> get_Prime(long K,long N){
	vector<bool> prime(N+1,true);
	prime[0]=prime[1]=false;

	for(long i=2;i*i<=N;i++){
		if(prime[i]){
			for(int j=2;i*j<=N;j++) prime[i*j]=false;
		}
	}

	vector<long> res;
	for(long i=K;i<=N;i++) if(prime[i]) res.push_back(i);

	return res;

}


int main(){

	long N;
	cin>>N;

	vector<long> prime=get_Prime(0,N);
	vector<long> is_kachi(N+1,false);

	//必要
	is_kachi[0]=is_kachi[1]=true;
	is_kachi[4]=true;


	for(long i=5;i<=N;i++){
		for(int j=0;prime[j]<=i && j<prime.size();j++){
			if(!is_kachi[i-prime[j]]){
				is_kachi[i]=true;
			}
		}
	}


	if(is_kachi[N]) cout<<"Win"<<endl;
	else cout<<"Lose"<<endl;

	return 0;
}
0