Skip to content

Instantly share code, notes, and snippets.

@EslaMx7
Created February 7, 2014 12:14
Show Gist options
  • Save EslaMx7/8861606 to your computer and use it in GitHub Desktop.
Save EslaMx7/8861606 to your computer and use it in GitHub Desktop.
Project Euler Problem 3 Solution with C#
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsolesTests
{
class Program
{
static void Main(string[] args)
{
long NUM = 600851475143;
long LargestPrime = 0;
// NUM = (long)Math.Sqrt(NUM);
for (long i = 2; i*i < NUM; i++)
{
if (IsFactorOf(NUM, i))
if (IsPrime(i))
{
Console.WriteLine(i + " : is prime & is factor ");
if (i > LargestPrime)
LargestPrime = i;
}
}
Console.WriteLine("\n Done.... and the Largest Prime Factor is : " +LargestPrime);
}
static bool IsPrime(long x) {
for (int i = 2; i < x;++i )
if (x % i == 0)
return false;
return true;
}
static bool IsFactorOf(long x, long y)
{
if (x % y == 0)
return true;
return false;
}
}
}
@emad-elsaid
Copy link

oh, i think this solution will take tooo much time doesn't it ? i tried this before and solution took about half an our on a code2due processor if i remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment