If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
(http://projecteuler.net/problem=1)
10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是23.
找出1000以下的自然数中,属于3和5的倍数的数字之和。
(http://pe.spiritzhang.com/index.php/2011-05-11-09-44-54/2-1100035)
只会用Perl:
#!perl -w use 5.010; use strict; my $sum; map {$sum += $_ } grep {$_ % 3 == 0 || $_ % 5 == 0} (1..999); say $sum;
感觉没啥好说的,很多人在讨论效率问题,感觉这个量的数据内,不需要。