結果

問題 No.7 プライムナンバーゲーム
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-12 11:23:19
言語 PHP
(8.3.4)
結果
AC  
実行時間 360 ms / 5,000 ms
コード長 689 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 32,272 KB
実行使用メモリ 32,656 KB
最終ジャッジ日時 2024-04-09 03:46:59
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
32,528 KB
testcase_01 AC 39 ms
32,400 KB
testcase_02 AC 360 ms
32,528 KB
testcase_03 AC 62 ms
32,532 KB
testcase_04 AC 45 ms
32,468 KB
testcase_05 AC 46 ms
32,400 KB
testcase_06 AC 132 ms
32,468 KB
testcase_07 AC 101 ms
32,276 KB
testcase_08 AC 67 ms
32,144 KB
testcase_09 AC 181 ms
32,400 KB
testcase_10 AC 40 ms
32,144 KB
testcase_11 AC 103 ms
32,528 KB
testcase_12 AC 268 ms
32,404 KB
testcase_13 AC 287 ms
32,532 KB
testcase_14 AC 360 ms
32,404 KB
testcase_15 AC 344 ms
32,656 KB
testcase_16 AC 317 ms
32,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$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, FALSE);
for ( $i=2; $i<=$n; $i++ ) {
	$win_flag = FALSE;
	for ( $j=0; $j<count($prime_array); $j++ ) {
		if ( $i-$prime_array[$j] < 0 ) {
			break;
		}
		if ( ($i-$prime_array[$j]) < 2 ) {
			continue;
		}
		if ( $result[$i-$prime_array[$j]] === FALSE ) {
			$win_flag = TRUE;
		}
	}
	$result[$i] = $win_flag;
}
if ( $result[$n] ) {
	echo 'Win'.PHP_EOL;
}
else {
	echo 'Lose'.PHP_EOL;
}
function is_prime($number) {
	for ( $i=2; $i<=sqrt($number); $i++ ) {
		if ( !($number % $i) ) {
			return FALSE;
		}
	}
	return TRUE;
}
0