結果

問題 No.7 プライムナンバーゲーム
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-12 11:23:19
言語 PHP
(7.2.24)
結果
AC  
実行時間 452 ms / 5,000 ms
コード長 689 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 18,540 KB
実行使用メモリ 18,884 KB
最終ジャッジ日時 2023-07-24 20:22:19
合計ジャッジ時間 4,960 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,856 KB
testcase_01 AC 15 ms
18,832 KB
testcase_02 AC 451 ms
18,880 KB
testcase_03 AC 43 ms
18,848 KB
testcase_04 AC 23 ms
18,840 KB
testcase_05 AC 23 ms
18,760 KB
testcase_06 AC 143 ms
18,864 KB
testcase_07 AC 102 ms
18,864 KB
testcase_08 AC 54 ms
18,840 KB
testcase_09 AC 209 ms
18,828 KB
testcase_10 AC 16 ms
18,820 KB
testcase_11 AC 103 ms
18,832 KB
testcase_12 AC 329 ms
18,700 KB
testcase_13 AC 350 ms
18,820 KB
testcase_14 AC 452 ms
18,816 KB
testcase_15 AC 429 ms
18,884 KB
testcase_16 AC 398 ms
18,844 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