ShareMyScreen/ProjectEuler/0001
Jump to navigation
Jump to search
For each divisor, count the number of multiples m below 1000. The sum of the integers from 1 to m is 0.5m2+0.5m. Multiply the sum by the divisor. Add the results, which will double-count the numbers that are multiples of both 3 and 5, i. e. multiples of 15. Repeat the procedure for a divisor of 15, and subtract that total.
Solution:
+/ 3 5 _15 * 0 0.5 0.5 p. <. 999 % 3 5 15
NB. slow-motion replay 999 % 3 5 15 NB. count multiples for each divisor 333 199.8 66.6 <. 999 % 3 5 15 NB. round down 333 199 66 0 0.5 0.5 p. <. 999 % 3 5 15 NB. calculate sum of integers 1..m for each m 55611 19900 2211 3 5 _15 * 0 0.5 0.5 p. <. 999 % 3 5 15 NB. multiply by m and choose sign 166847 99500 _33165 +/ 3 5 _15 * 0 0.5 0.5 p. <. 999 % 3 5 15 NB. final total - no spoiler! 233182