// 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?
using System;
using System.Collections.Generic;
using System.Text;
namespace projecteuler005
{
class Program
{
static void Main(string[] args)
{
F1();
}
private static void F1()
{
Console.WriteLine(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod());
DateTime timeStart = DateTime.Now;
int maxValue = 20;
long lcm = 1;
for (int i = 2; i <= maxValue; i++)
{
lcm = LCM(lcm, i);
}
Console.WriteLine(lcm);
Console.WriteLine("Total Milliseconds is " + DateTime.Now.Subtract(timeStart).TotalMilliseconds + "
");
}
/// <summary>
/// 2
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
private static long GCM(long a, long b)
{
if (a % b == 0)
{
return b;
}
return GCM(b, a % b);
}
/// <summary>
/// 2
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
private static long LCM(long a, long b)
{
return a * b / GCM(a, b);
}
}
}
/*
Void F1()
232792560
Total Milliseconds is 7.0009
By GodMoon
*/