I want to run something like below code so that i would be able to find a divisor for numbers of ~30-40 length without having to check millions of possibilities even up to their square root. What is the fastest possible solution to find a legitimate divisor of a number without having to loop through all possible ones.
static int divisor(string numberToCheck)
{
BigInteger n = BigInteger.Parse(numberToCheck);
BigInteger sqrt = Sqrt(n);
if (n % 2 == 0)
retu 2;
for (UInt64 = 3; i <= sqrt; i+=2)
{
if (n % i == 0)
retu i;
}
retu -1;
}
برچسب:
نویسنده: استخدام کار