結果

問題 No.7 プライムナンバーゲーム
ユーザー 綾地寧々
提出日時 2015-06-05 13:20:49
言語 PHP
(843.2)
結果
WA  
実行時間 -
コード長 701 bytes
コンパイル時間 1,376 ms
コンパイル使用メモリ 31,116 KB
実行使用メモリ 31,664 KB
最終ジャッジ日時 2024-07-06 14:11:16
合計ジャッジ時間 2,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$starttime = microtime(TRUE);
$n = trim(fgets(STDIN));
$prime_array = array();
for ( $i=2; $i<=$n; $i++ ) {
	if ( is_prime($i) ) {
		$prime_array[] = $i;
	}
}
$sub_count = 0;
while ( $n >= 4 ) {
	for ( $i=(count($prime_array)-1); $i>=0; $i-- ) {
		if ( ($n - $prime_array[$i]) >= 2 ) {
			break;
		}
	}
	$n -= $prime_array[$i];
	$sub_count++;
}
fprintf(STDERR, "sub_count: %d\n", $sub_count);
if ( $sub_count % 2 ) {
	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;
}

$exectime = microtime(TRUE) - $starttime;
fprintf(STDERR,"%f seconds\n", $exectime);
0