The solution given below is running for integers but is not giving any output for really long digits. Still trying to figure out a solution.
/*
What is the largest prime factor of the number 600851475143 ?
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Check4Prime
{
public bool checkprime(long a)
{
bool prime = true;
for (long i = a - 1; i > 1; i--)
{
if (a % i == 0)
{
prime = false;
}
}
return prime;
}
}
class Program
{
static void Main(string[] args)
{
long number = 600851475143;
int j=1;
Check4Prime c = new Check4Prime();
for (long factor = number - 1; factor > 1; factor--)
{
if (number % factor == 0)
{
if (c.checkprime(factor))
{
Console.WriteLine(" Prime factor number " + j++ + "of " + number + " is " + factor);
}
}
}
}
}
}