数値 104751475143 が 1 秒未満で計算され、数値 251475141 がより長い時間かかる理由を誰か教えてもらえますか? コードは最大の因数を見つけようとしています。
これは私のコードです。
long long lrgPFactor = 0;
long long currentfactor = 0;
long long tempfactor = 0;
long long Number = 251475141;
long long factor = 0;
switch ((long long)sqrt(Number)%2) //skipping to the square root of the number to save time
{
case 0: factor=((long long)sqrt(Number)-1); break; //If even make it odd
default: factor=((long long)sqrt(Number)); break; //If odd leave it
}
while (factor > 0)
{
if (Number % factor == 0) //if factor is a factor
{
factor=Number/factor; //make the factor the larger of the pair
switch ((long long)sqrt(factor)%2) //same as above
{
case 0: tempfactor=((long long)sqrt(factor)-1); break;
default: tempfactor=((long long)sqrt(factor)); break;
}
for (tempfactor = factor - 1; tempfactor > 1; --tempfactor) //simple way to determine if prime
{
if (factor % tempfactor == 0)
break;
}
if (tempfactor == 1)
{
lrgPFactor = factor;
break;
}
}
factor -= 2;
}