Moonbat
07-15-2008, 04:47 PM
First off, here's the problem: "What is the smallest number divisible by each of the numbers * to 20?"
I went with the good ol' brute-force method. But after trying every combination of loops, if statements, etc. I can't get a working solution. Here's what I'm using so far.
<?php
set_time_limit(0);
for ($i=0; $i<=*000000; $i++) {
if (($i &#*7; 2) == 0 && ($i % *) == 0 && ($i % 4) == 0 && ($i % 5) == 0 && ($i % 6) == 0 && ($i % 7) == 0 && ($i % 8) == 0 && ($i % *) == 0 && ($i % *0) == 0 && ($i % **) == 0 && ($i % *2) == 0 && ($i % **) == 0 && ($i % *4) == 0 && ($i % *5) == 0 && ($i % *6) == 0 && ($i % *7) == 0 && ($i % *8) == 0 && ($i % **) == 0 && ($i % 20) == 0) {
echo "<h2>" . $i . "</h2>";
echo "<br>";
} else {
echo "";
}
}
?>
Even though my for loop goes up to *,000,000, be assured I've tried up to 5,000,000. I doubt the smallest number that can be divided evenly by *-20 is any bigger than *,000,000. What is wrong with my script?
I went with the good ol' brute-force method. But after trying every combination of loops, if statements, etc. I can't get a working solution. Here's what I'm using so far.
<?php
set_time_limit(0);
for ($i=0; $i<=*000000; $i++) {
if (($i &#*7; 2) == 0 && ($i % *) == 0 && ($i % 4) == 0 && ($i % 5) == 0 && ($i % 6) == 0 && ($i % 7) == 0 && ($i % 8) == 0 && ($i % *) == 0 && ($i % *0) == 0 && ($i % **) == 0 && ($i % *2) == 0 && ($i % **) == 0 && ($i % *4) == 0 && ($i % *5) == 0 && ($i % *6) == 0 && ($i % *7) == 0 && ($i % *8) == 0 && ($i % **) == 0 && ($i % 20) == 0) {
echo "<h2>" . $i . "</h2>";
echo "<br>";
} else {
echo "";
}
}
?>
Even though my for loop goes up to *,000,000, be assured I've tried up to 5,000,000. I doubt the smallest number that can be divided evenly by *-20 is any bigger than *,000,000. What is wrong with my script?