I have a new algorithm to find factors or primes in linear time - need verification for this

不问归期 提交于 2019-12-06 22:38:23

问题


I have developed an algorithm to find factors of a given number. Thus it also helps in finding if the given number is a prime number. I feel this is the fastest algorithm for finding factors or prime numbers.

This algorithm finds if a give number is prime in time frame of 5*N (where N is the input number). So I hope I can call this a linear time algorithm.

How can I verify if this is the fastest algorithm available? Can anybody help in this matter? (faster than GNFS and others known)

Algorithm is given below

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

Please provide your comments.. dont hesitate to contact me for any more information.

Thanks, Harish http://randomoneness.blogspot.com/2011/09/algorithm-to-find-factors-or-primes-in.html


回答1:


"Linear time" means time proportional to the length of the input data: the number of bits in the number you're trying to factorize, in this case. Your algorithm does not run in linear time, or anything close to it, and I'm afraid it's much slower than many existing factoring algorithms. (Including, e.g., GNFS.)




回答2:


The size of the input in this case is not n, but the number of bits in n, so the running time of your algorithm is exponential in the size of the input. This is known as pseudo-polynomial time.




回答3:


I haven't looked closely at your algorithm, but prime number tests are usually faster than O(n) (where n is the input number). Take for example this simple one:

def isprime(n):
   for f in range(2,int(sqrt(n))):
      if n % f == 0:
         return "not prime"
   return "prime"

Here it is determined in O(sqrt(n)) if n is prime or not, simply by checking all possible factors up to sqrt(n).



来源:https://stackoverflow.com/questions/5581040/i-have-a-new-algorithm-to-find-factors-or-primes-in-linear-time-need-verificat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!