結果

問題 No.6 使いものにならないハッシュ
ユーザー mino_yellowmino_yellow
提出日時 2022-11-16 02:47:44
言語 PHP
(8.3.4)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 1,085 bytes
コンパイル時間 3,129 ms
コンパイル使用メモリ 32,664 KB
実行使用メモリ 36,684 KB
最終ジャッジ日時 2023-10-17 02:30:25
合計ジャッジ時間 7,594 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
32,776 KB
testcase_01 AC 40 ms
32,776 KB
testcase_02 AC 68 ms
36,684 KB
testcase_03 AC 44 ms
32,776 KB
testcase_04 AC 47 ms
34,636 KB
testcase_05 AC 48 ms
32,776 KB
testcase_06 AC 56 ms
36,684 KB
testcase_07 AC 51 ms
34,636 KB
testcase_08 AC 55 ms
36,684 KB
testcase_09 AC 51 ms
36,684 KB
testcase_10 AC 40 ms
32,776 KB
testcase_11 AC 45 ms
32,776 KB
testcase_12 AC 59 ms
36,684 KB
testcase_13 AC 52 ms
36,684 KB
testcase_14 AC 53 ms
36,684 KB
testcase_15 AC 58 ms
34,732 KB
testcase_16 AC 54 ms
36,684 KB
testcase_17 AC 61 ms
36,684 KB
testcase_18 AC 67 ms
36,684 KB
testcase_19 AC 61 ms
36,684 KB
testcase_20 AC 72 ms
36,684 KB
testcase_21 AC 44 ms
32,776 KB
testcase_22 AC 60 ms
36,684 KB
testcase_23 AC 65 ms
36,684 KB
testcase_24 AC 59 ms
36,684 KB
testcase_25 AC 52 ms
34,636 KB
testcase_26 AC 63 ms
36,684 KB
testcase_27 AC 58 ms
36,684 KB
testcase_28 AC 51 ms
34,636 KB
testcase_29 AC 64 ms
36,684 KB
testcase_30 AC 63 ms
36,684 KB
testcase_31 AC 61 ms
36,684 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
fscanf(STDIN,"%d",$K);
fscanf(STDIN,"%d",$N);
$p = sosuFlags($N);
$memo = [];
for($i=0,$n=count($p);$i<$n;++$i) $ph[] = hash_($p[$i]);

$max = [-1,-1];
for($i=0;$i<$n;++$i){
    $nums = [];
    $j = $i;
    while($j < $n && !isset($nums[$ph[$j]])){
        $nums[$ph[$j]] = true;
        ++$j;
    }
    if($j-$i >= $max[0]){
        $max[0] = $j-$i;
        $max[1] = $i;
    }
}

echo $p[$max[1]] . PHP_EOL;


function hash_($x){
    global $memo;
    $x = strval($x);
    if(isset($memo[$x])) return $memo[$x];
    $num = 0;
    for($i=0,$len=strlen($x);$i<$len;++$i) $num += $x[$i];
    if($num < 10){
        $memo[$x] = $num;
        return $num;
    }else{
        $memo[$x] = hash_($num);
        return $memo[$x];
    }
}

function sosuFlags($x){
    global $K;
    $flags = array_fill(0,$x+1,true);
    $flags[0] = $flags[1] = false;
    $sq = ceil(sqrt($x));
    for($i=2;$i<$sq;++$i){
        if(!$flags[$i]) continue;
        for($j=$i*$i;$j<=$x;$j+=$i) $flags[$j] = false;
    }
    $a = [];
    for($i=$K;$i<=$x;++$i) if($flags[$i]) $a[] = $i;
    return $a;
}

?>
0