|
-
Jul 18th, 2009, 11:29 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] What's wrong here?
The assignment:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
My code:
PHP Code:
<center>
<?PHP
function isPrime($num) {
for ($i = $num-1; $i > 1; $i--)
if ($num % $i == 0) return false;
return true;
}
$num = 600851475143;
for ($x = $num-1; $x > $num; $x--)
if (($num % $x == 0) && isPrime($x))
die(strval($x));
?>
</center>
It just shows a white screen...
Edit: the &# 37 is a % in my code... not sure why it's doing that
Last edited by penagate; Jul 20th, 2009 at 12:37 AM.
Reason: fixed the % sign!
-
Jul 19th, 2009, 12:24 AM
#2
Thread Starter
Frenzied Member
Re: What's wrong here?
Here is what I see when I view source:
-
Jul 19th, 2009, 02:57 AM
#3
Re: What's wrong here?
Looks like there's some faulty logic here:
Code:
for ($x = $num-1; $x > $num; $x--)
$x initially equals $num minus 1, but your loop condition is while $x is greater than $num.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|