introduction screenshots faq forum blog modules components download
Please use the search function and/or read the FAQ first.

Go to Topic: PreviousNext
Go to: Message ListNew TopicSearchLog InPrint View

Certain number crashes prime-factoring program



Posted by: Jskid
April 20, 2010 09:35PM
This problem only exists with EasyPHP 1.8.
I wrote this program along time ago and I realize my style was very poor.
The program takes an integer ($num) and prime factors it. The numbers 15999 and 2702811 cause the server to crash (apperantly) immediately.

<?php
print("Start of program");
$num = 15989;
$startnum = 1;
if($num == 1){
print("1 has no factors");
exit;
}
if($num == 0){
print("0 has no factors");
exit
}else{
print("The factors of ".$num." are:<br />");
}
primefind($num, $startnum);
if($num == 0){
print("0");
}
else if($num == 1){
print("1");
}else{
}
function primefind($num, $startnum){
$primestat = 'f';
for($counter1 = $startnum; $counter1<=$num; $counter1++){
for($counter2 = 2; $counter2<$counter1; $counter2++){
$primecheck = $counter1%$counter2;
if($primecheck != 0){
$primestat = 't';
}else{
$primestat = 'f';
break;
}
}
if($primestat == 't'||$counter1 == 2){
factorcheck($counter1, $num);
break;
}
}
}
function factorcheck($prime, $num){
$remainder = $num%$prime;
if($remainder == 0)
{
print($prime.'<br />');
$startnum = 1;
primefind(($num/$prime), $startnum);
//exit;
return $prime;
}
else{
$prime++;
primefind($num, $prime);
}
}
?>
Options: ReplyQuote


Go to: Message ListSearchLog In
Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.