Hi ..am new to PHP and am using it to solve some mathematical problems which require extensive computation.
Following is a code to solve a problem:
<?php
$num =1;
$n =0;
$temp = 0;
$count =0;
$Final =0;
While( $num < [color=orange]1000000)[/color]
{
$n = $num;
while($n >1)
{
if(( $n % 2) == 0)
{
$n = $n/2;
$temp++;
}
else
{
$n =3*$n +1;
$temp++;
}
}
If($temp > $count)
{
$count =$temp;
$Final =$num;
}
$num++;
$temp =0;
}
echo $Final;
echo "<BR>";
echo $count;
?>
I am running into "Maximum execution time of 30 seconds exceeded" error...its happening coz of the number 1 million...the code wrks fine for 100,1000,10000 and 100000...but breaks down @ 1000000.....is there any way to solve this situation...or PHP is not capable of handling huge numbers?
please help...am stuck with this even though am so close to solving the prob.
Thanks
Abhijeet