Problem 5 from Project Euler:
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 positive number that is evenly divisible by all of the numbers from 1 to 20?
DECLARE c_step PLS_INTEGER := 20; v_sn PLS_INTEGER := c_step; aed BOOLEAN := FALSE; ed BOOLEAN; BEGIN WHILE (NOT aed) LOOP ed := TRUE; FOR i in 2..c_step LOOP IF mod(v_sn,i) <> 0 THEN ed := FALSE; EXIT; END IF; END LOOP; IF ed THEN aed := TRUE; ELSE v_sn := v_sn + c_step; END IF; END LOOP; dbms_output.put_line('sn: '||v_sn); END;
As always.. I am no mathmatician, so If you know of a better solution please let me know.