Skip to content

Instantly share code, notes, and snippets.

@AbdallaZaki
Last active August 29, 2015 14:06
Show Gist options
  • Save AbdallaZaki/ce54ccff95ee1a06236b to your computer and use it in GitHub Desktop.
Save AbdallaZaki/ce54ccff95ee1a06236b to your computer and use it in GitHub Desktop.
Project Euler problem 5
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