我开发了一种算法来查找给定数字的因子.因此,它还有助于查找给定数字是否为素数.我觉得这是查找因子或素数的最快算法.
该算法在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 …Run Code Online (Sandbox Code Playgroud)