Friday 10 April 2009

PROJECT EULER #5

Link to Project Euler problem 5

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?

It's enought to test for 20 down to 11 as this automatically includes the rest.


using System;

namespace ProjectEuler
{
class Program
{
static void Main(string[] args)
{
//Problem 5
DateTime start = DateTime.Now;
bool test = false;
int i=0;
do
{
i++;
test = i%20 == 0 && i%19 == 0 && i%18 == 0 && i%17 == 0 && i%16 == 0 &&
i%15 == 0 && i%14 == 0 && i%13 == 0 && i%12 == 0 && i%11 == 0
? true
: false;
} while (!test);
TimeSpan time = DateTime.Now-start;
Console.WriteLine("{0}\nThis took {1}",i ,time);
Console.ReadKey();
}
}
}
0

No comments: