結果

問題 No.7 プライムナンバーゲーム
ユーザー DevbotBotDevbotBot
提出日時 2015-07-24 11:32:24
言語 PHP
(8.3.4)
結果
AC  
実行時間 632 ms / 5,000 ms
コード長 627 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 32,016 KB
実行使用メモリ 32,656 KB
最終ジャッジ日時 2024-04-09 03:48:14
合計ジャッジ時間 5,393 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
32,528 KB
testcase_01 AC 38 ms
32,400 KB
testcase_02 AC 632 ms
32,656 KB
testcase_03 AC 73 ms
32,532 KB
testcase_04 AC 47 ms
32,404 KB
testcase_05 AC 46 ms
32,400 KB
testcase_06 AC 202 ms
32,528 KB
testcase_07 AC 147 ms
32,528 KB
testcase_08 AC 85 ms
32,400 KB
testcase_09 AC 294 ms
32,340 KB
testcase_10 AC 38 ms
32,404 KB
testcase_11 AC 148 ms
32,528 KB
testcase_12 AC 456 ms
32,400 KB
testcase_13 AC 485 ms
32,404 KB
testcase_14 AC 628 ms
32,528 KB
testcase_15 AC 597 ms
32,528 KB
testcase_16 AC 550 ms
32,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$max = trim(fgets(STDIN));
$prime_array = array();
for($n=2; $n<$max; $n++)
{   for($i=floor($n/2); $n%$i!=0; $i--);
    if ($i==1){
        $prime_array[] = $n;
    }
}
$result = array_fill(0, $max+1, 0);
for ( $i=2; $i<=$max; $i++ ) {
        $win_flag = 0;
    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]] < 1 ) {
            $win_flag = 1;
        }
    }
    $result[$i] = $win_flag;
}
echo ($result[$n]? 'Win':'Lose') . PHP_EOL;
0