結果

問題 No.7 プライムナンバーゲーム
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-11 12:22:15
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 18,680 KB
実行使用メモリ 19,048 KB
最終ジャッジ日時 2023-09-20 20:46:01
合計ジャッジ時間 4,057 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,980 KB
testcase_01 AC 16 ms
18,908 KB
testcase_02 AC 471 ms
18,884 KB
testcase_03 WA -
testcase_04 AC 23 ms
18,952 KB
testcase_05 AC 22 ms
18,772 KB
testcase_06 WA -
testcase_07 AC 104 ms
18,956 KB
testcase_08 WA -
testcase_09 AC 213 ms
18,956 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 337 ms
18,884 KB
testcase_13 AC 359 ms
18,932 KB
testcase_14 AC 464 ms
18,888 KB
testcase_15 WA -
testcase_16 AC 409 ms
19,020 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
define("NOT_REACHED", 0);
define("REACHED", 3);
define("REACH_EVEN", 1);
define("REACH_ODD", 2);
$n = trim(fgets(STDIN));
$prime_array = array();
for ( $i=2; $i<=$n; $i++ ) {
	if ( is_prime($i) ) {
		$prime_array[] = $i;
	}
}
$result = array_fill(0, $n+1, NOT_REACHED);
$result[$n] = REACH_EVEN;
for ( $i=$n; $i>=0; $i-- ) {
	if ( $result[$i] === NOT_REACHED ) {
		continue;
	}
	for ( $j=0; $j<count($prime_array); $j++ ) {
		if ( $i-$prime_array[$j] < 0 ) {
			break;
		}
		switch ( $result[$i] ) {
			case REACH_EVEN:
				$result[$i-$prime_array[$j]] |= REACH_ODD;
				break;
			case REACH_ODD:
				$result[$i-$prime_array[$j]] |= REACH_EVEN;
				break;
			case REACHED:
			default:
			break;
		}
	}
}
if ( ($result[0] == REACH_ODD ) || ($result[1] == REACH_ODD)  ) {
	echo 'Lose'.PHP_EOL;
}
else {
	echo 'Win'.PHP_EOL;
}
function is_prime($number) {
	for ( $i=2; $i<=sqrt($number); $i++ ) {
		if ( !($number % $i) ) {
			return FALSE;
		}
	}
	return TRUE;
}
0