Project Euler – Problem 1

By | May 12, 2011

Problem 1 from Project Euler:

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.

My solution:

DECLARE
    v_sum PLS_INTEGER := 0;
    c_max CONSTANT PLS_INTEGER := 1000;
BEGIN
    FOR i IN 1 .. c_max - 1
    LOOP
        IF mod(i,3) = 0 or mod(i,5) = 0
        THEN
            v_sum := v_sum + i;
        END IF;
    END LOOP;
    dbms_output.put_line('sum: '||v_sum);
END;

Again, I am no mathmatician, so If you know of a better solution please let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *

Turn on pictures to see the captcha *