[Tutor] Add all natural numbers that are multiples of 3 and 5
bob gailer
bgailer at gmail.com
Sun Jan 4 19:54:36 CET 2009
Alan Gauld wrote:
> "bob gailer" <bgailer at gmail.com> wrote
>
>> Also consider that the sum of consecutive integers between 1 and n is
>> n*(n+1)/2.
>> Calculate that for 1..333 then multiply by 3
>> Calculate that for 1..199 then multiply by 5
>> add those
>> Calculate that for 1..66 then multiply by 15
>> subtract that from the total
>
> Ooh, that's sneaky! I haven't seen that before.
Guess you did not study number theory. Standard algorithm. Google sum of
consecutive integers.
Regarding Project Euler - I believe one of the objectives is to find
solutions that are not just brute force. Some of the problems can be
solved by brute force but will take too much computer time. Sphere
Online Judge www.spoj.pl is even more rigorous in that it runs your
program and if run time is too long the solution is considered not correct.
--
Bob Gailer
Chapel Hill NC
919-636-4239
More information about the Tutor
mailing list