Last active
October 23, 2015 20:39
-
-
Save deniskyashif/f3206659121ea8ce762f to your computer and use it in GitHub Desktop.
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; | |
class Program | |
{ | |
private const ulong N = 600851475143; | |
static void Main() | |
{ | |
bool[] composites = new bool[(ulong)Math.Sqrt(N)]; | |
ulong length = (ulong)composites.Length; | |
ulong lpf = 1; | |
// sieve of Eratosthenes algorithm | |
for (ulong i = 2; (i * i) < length; i++) | |
{ | |
if (!composites[i]) | |
{ | |
for (ulong k = i; (i * k) < length; k++) | |
{ | |
composites[i*k] = true; | |
} | |
} | |
} | |
for (ulong i = length - 1; i > 1; i -= 2) | |
{ | |
if (!composites[i] && (N % i) == 0) | |
{ | |
lpf = i; | |
break; | |
} | |
} | |
Console.WriteLine(lpf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment