結果

問題 No.7 プライムナンバーゲーム
ユーザー bal4ubal4u
提出日時 2019-05-25 20:47:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 660 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 32,896 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:38:29
合計ジャッジ時間 979 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: 7 プライムナンバーゲーム
// 2019.5.25 bal4u

#include <stdio.h>
#include <math.h>
#include <string.h>

#define MAX 10000
char prime[MAX+10];

void sieve(int n) {
	int i, j, k;
	
	memset(prime+2, 1, n);
//	for (i = 4; i <= n; i += 2) prime[i] = 0;
	k = (int)sqrt((double)n);
	for (i = 3; i <= k; i += 2) if (prime[i])
		for (j = i*i; j <= n; j +=i ) prime[j] = 0;
}

char f[MAX+10];

int main()
{
	int N, i, j;
	
	scanf("%d", &N);
	sieve(N);
	for (i = 2; i < N; i++) if (!f[i]) {
		f[i+2] = 1;
		for (j = 3; i+j <= N; j+=2) if (prime[j]) {
			f[i+j] = 1;
			if (i+j == N) goto done;
		}
	}
done:
	puts(f[N]? "Win": "Lose");
	return 0;
}
0