Last active
August 29, 2015 14:06
-
-
Save AbdallaZaki/ce54ccff95ee1a06236b to your computer and use it in GitHub Desktop.
Project Euler problem 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Algo1 | |
{ | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
// Stopwatch stopwatch = Stopwatch.StartNew(); | |
// stopwatch.Start(); | |
int maxnum = 20; | |
int num = 2; | |
for (int i = num; i <= int.MaxValue; i += 2) | |
{ | |
int tmp = GetNum(i, maxnum); | |
if ( tmp!= 0) | |
{ | |
num = tmp; | |
break; | |
} | |
} | |
// stopwatch.Stop(); | |
Console.WriteLine("The Number : "+num); | |
// Console.WriteLine("Time in Milliseconds : "+stopwatch.ElapsedMilliseconds); | |
Console.ReadKey(); | |
} | |
public static int GetNum (int num,int maxnum) | |
{ | |
for (var i = 2; i <= maxnum; i++) | |
{ | |
if (num % i != 0) | |
{ | |
return 0; | |
} | |
if (i == maxnum) | |
{ | |
return num; | |
} | |
} | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment