Abhyro Posted May 22, 2011 Share Posted May 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237107-handling-big-numbers/ Share on other sites More sharing options...
ignace Posted May 22, 2011 Share Posted May 22, 2011 set_time_limit: set_time_limit(0); makes your script run indefinitely Quote Link to comment https://forums.phpfreaks.com/topic/237107-handling-big-numbers/#findComment-1218674 Share on other sites More sharing options...
Abhyro Posted May 22, 2011 Author Share Posted May 22, 2011 Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/237107-handling-big-numbers/#findComment-1218762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.