# [OT]有没有无聊逛TheDailyWTF的朋友？

1 view

### est

Oct 10, 2008, 11:10:32 AM10/10/08
to TopLanguage

2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the
numbers from 1 to 20?

"When we interview people," cablecar wrote on the Sidebar, "we give
them simple programming tasks to test their ability. The below code
was an attempt to solve a problem I found on Project Euler. It's from
a candidate for a senior development position with '10 years of PHP'
experience.

for (\$i=1;\$i<=99999999999;\$i++) {
\$num = 20*\$i;
if (\$num%19 == 0) {
if (\$num%18 == 0) {
if (\$num%17 == 0) {
if (\$num%16 == 0) {
if (\$num%15 == 0) {
if (\$num%14 == 0) {
if (\$num%13 == 0) {
if (\$num%12 == 0) {
if (\$num%11 == 0) {
if (\$num%9 == 0) {
if (\$num%8 == 0) {
if (\$num%7 == 0) {
if (\$num%6 == 0) {
if (\$num%3 == 0) {
echo \$num;
exit();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
"Yeah, it works, but..."

### Changsheng Jiang

Oct 10, 2008, 11:20:25 AM10/10/08
lcm(1, 2, ..., 20) = 2^4 * 3^2 * 5 * 7 * 11 * 13 * 17 * 19

Yours sincerely,
Changsheng Jiang

2008/10/10 est