I am trying to complete this challenge, which is to find the Find the largest Prime Factor of the number 600851475143.
My current solution is below:
static void Main(string[] args)
{
const long targetNumber = 600851475143;
var primeFactors = new List<long>();
for (long i = 1; i <= targetNumber; i++)
{
if(PrimeFactor(targetNumber, i))
{
primeFactors.Add(i);
}
}
var biggestPrimeFactor = primeFactors.Max();
Console.WriteLine(biggestPrimeFactor);
Console.ReadLine();
}
public static bool PrimeFactor(long number, long i)
{
return number % i == 0;
}
My main problem is that this is taking ages to run, but it's also not very eloquent.
How can I improve on the above?
Thanks

