Answer the question
In order to leave comments, you need to log in
Calculation of Fermat numbers. Why so slow?
Hello freshly baked friends sitting in the toaster.
I have such a problem: I decided for the sake of fun to "search" the Fermat numbers. Used System.Numerics.BigInteger. The methods of this structure had Pow, but it could raise to the power of Int32, so I built such a crutch:
static BigInteger PPow(byte num, BigInteger exp)
{
BigInteger result = 1;
uint n = (uint)(exp / Int32.MaxValue);
Parallel.For(0, n, i =>
{
lock (lockobj)
{
result *= BigInteger.Pow(num, Int32.MaxValue);
exp -= Int32.MaxValue;
}
});
result *= BigInteger.Pow(num, (int)exp);
return result;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question