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

1 view
Skip to first unread message

est

unread,
Oct 10, 2008, 11:10:32 AM10/10/08
to TopLanguage
貌似现在有些公司招聘用 ProjectEuler 上的题目出题啊。比如这个 http://projecteuler.net/index.php?section=problems&id=5

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?

某囧人给的答案

http://thedailywtf.com/Articles/Out-of-All-the-Possible-Answers.aspx


"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

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

Yours sincerely,
Changsheng Jiang


2008/10/10 est <electr...@gmail.com>

Teng Ren

unread,
Oct 10, 2008, 1:30:55 PM10/10/08
to pon...@googlegroups.com
我在想,他能把2 4 5省掉,为啥不能把3 6 8 9省掉。。。

2008/10/10 Changsheng Jiang <jiang...@gmail.com>
Reply all
Reply to author
Forward
0 new messages