Project Euler Problem 5
This one takes three or four seconds to run, so it’s a likely candidate for a rewrite.
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 number that is evenly divisible by all of the numbers from 1 to 20?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Project_Euler_5 { class Program { static void Main(string[] args) { new Program(); } Program() { for (int i = 1; ; i++) { if(isEvenlyDivisibleByRange(i, 11, 20)) { Console.WriteLine(i); Console.ReadKey(); } } } bool isEvenlyDivisibleByRange(int value, int lowerBound, int upperBound) { for (int i = lowerBound; i <= upperBound; i++) if (value % i != 0) return false; return true; } } } |



looks like not enough math! REDO with more math, less loops!