結果

問題 No.7 プライムナンバーゲーム
ユーザー zuvizudarzuvizudar
提出日時 2016-12-28 23:29:36
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 525 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 24,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 20:43:23
合計ジャッジ時間 1,293 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>
int memo[10001];
int prime[10001];
int dp[10001];
int p[5001];

int primech(int n);

int main(){
	int n,i,j,count=0;
	scanf("%d",&n);
	for(i=2;i<=n;i++){
		if(primech(i)==1){
			prime[i]=1;
			p[count]=i;
			count++;
		}
	}
	dp[0]=1;
	dp[1]=1;
	for(i=2;i<=n;i++){
		j=0;
		while(p[j]<=i&&j<count){
			if(dp[i-p[j]]==0)
				dp[i]=1;
			
			j++;
		}
	}

	if(dp[n]==1)printf("Win\n");
	else printf("Lose\n");

	return 0;
}

int primech(int n){
	int i;
	for(i=2;i<n;i++){
		if(n%i==0) return 0;
	}
	return 1;
}
0