Reputation: 342
Folks i have a sample console application which has a method that calculates the factors of the given number and returns the same as list.
If the input number is less than 9 digits the program is working fine however if the number is a 12 digit number, the execution goes on forever and there is no output and no exceptions also.
I have attached the execution code...
static void Main(string[] args)
{
var list = GetFactors(600851475143);
}
static List<long> GetFactors(long bigNum)
{
var list = new List<long>();
long counter = 1;
try
{
while (counter <= bigNum / 2)
{
if (bigNum % counter == 0)
{
list.Add(counter);
}
counter++;
}
}
catch (Exception ex)
{
throw;
}
return list;
}
Upvotes: 0
Views: 123
Reputation: 3915
...which is to be expected. Most of cryptographic algorithms are based on how computationally expensive it is to compute (prime) factors of a given number. The increment in the cost is not linear, so most likely, the jump between 9 and 12 digits is too big (with that unoptimized algorithm) that you won't be able to see the result anytime soon.
There are several documents about it on the net, just one among them many: http://computer.howstuffworks.com/computing-power.htm
Upvotes: 3