Add tags

Add tags to the following comment

愚直に。 答えが出るまで数十分かかります。 PHP遅すぎる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$max = array(1,0);
$maxValue = pow(2,20);

for($i=1;$i<=$maxValue;$i++){
    $deep = collatz($i);
    if($max[1] < $deep){
        $max[0] = $i;
        $max[1] = $deep;
    }
}
echo "n=" . $max[0] . " f(n)=" . $max[1];

function collatz($value, $deep = 0){
    if($value == 1){
        return $deep;
    }elseif($value%2 == 0){
        $deep = collatz($value/2, $deep);
    }else{
        $deep = collatz($value*3+1, $deep);
    }
    return $deep + 1;
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...