我开发了一种算法来查找给定数字的因子。因此,它还有助于确定给定数字是否为素数。我觉得这是寻找因子或素数的最快算法。
该算法确定给定数字是否在 5*N 的时间范围内是素数(其中 N 是输入数字)。所以我希望我可以称之为线性时间算法。
如何验证这是否是可用的最快算法?有人可以帮忙吗?(比 GNFS 和其他已知的更快)
算法如下
Input: A Number (whose factors is to be found)
Output: The two factor of the Number. If the one of the factor found is 1 then it can be concluded that the
Number is prime.
Integer N, mL, mR, r;
Integer temp1; // used for temporary data storage
mR = mL = square root of (N);
/*Check if perfect square*/
temp1 = mL * mR;
if temp1 equals N then
{
r = 0; //answer is found
End;
}
mR = N/mL; (have the value of mL less than mR)
r = N%mL;
while r not equals 0 do
{
mL = mL-1;
r = r+ mR;
temp1 = r/mL;
mR = mR + temp1;
r = r%mL;
}
End; //mR and mL has answer
请提供您的意见.. 不要犹豫与我联系以获取更多信息。
谢谢,Harish http://randomoneness.blogspot.com/2011/09/algorithm-to-find-factors-or-primes-in.html