请输入您要查询的百科知识:

 

词条 Trial division
释义

  1. Method

  2. Speed

  3. References

  4. External links

{{About|the mathematical algorithm|the judicial chamber of the International Criminal Court|Judges of the International Criminal Court}}{{citations|date=March 2014}}

Trial division is the most laborious but easiest to understand of the integer factorization algorithms. The essential idea behind trial division tests to see if an integer n, the integer to be factored, can be divided by each number in turn that is less than n. For example, for the integer {{math|1=n {{=}} 12}}, the only numbers that divide it are 1, 2, 3, 4, 6, 12. Selecting only the largest powers of primes in this list gives that {{math|1=12 {{=}} 3 × 4 {{=}} 3 × 22}}.

Trial division was first described by Fibonacci in his book Liber Abaci (1202).[1]

Method

Given an integer n (n refers to "the integer to be factored"), trial division consists of systematically testing whether n is divisible by any smaller number. Clearly, it is only worthwhile to test candidate factors less than n, and in order from two upwards because an arbitrary n is more likely to be divisible by two than by three, and so on. With this ordering, there is no point in testing for divisibility by four if the number has already been determined not divisible by two, and so on for three and any multiple of three, etc. Therefore, effort can be reduced by selecting only prime numbers as candidate factors. Furthermore, the trial factors need go no further than because, if n is divisible by some number p, then n = p × q and if q were smaller than p, n would have been detected earlier as being divisible by q or by a prime factor of q.

A definite bound on the prime factors is possible. Suppose Pi is the i'th prime, so that P1 = 2, P2 = 3, P3 = 5, etc. Then the last prime number worth testing as a possible factor of n is Pi where P2i + 1 > n; equality here would mean that Pi + 1 is a factor. Thus, testing with 2, 3, and 5 suffices up to n = 48 not just 25 because the square of the next prime is 49, and below n = 25 just 2 and 3 are sufficient. Should the square root of n be integral, then it is a factor and n is a perfect square.

An example of the trial division algorithm, using successive integers as trial factors, is as follows (in Python):

def trial_division(n):

"""Return a list of the prime factors for a natural number."""

a = [] #Prepare an empty list.

f = 2 #The first possible factor.

while n > 1: #While n still has remaining factors...

if n % f == 0: #The remainder of n divided by f might be zero.

a.append(f) #If so, it divides n. Add f to the list.

n /= f #Divide that factor out of n.

else: #But if f is not a factor of n,

f += 1 #Add one to f and try again.

return a #Prime factors may be repeated: 12 factors to 2,2,3.

Or 2x more efficient:

def trial_division(n):

    a = []      while n % 2 == 0:        a.append(2)        n /= 2    f = 3    while f * f <= n:        if n % f == 0:            a.append(f)            n /= f        else:            f += 2       if n != 1: a.append(n)    #Only odd number is possible    return a

These versions of trial division are guaranteed to find a factor of n if there is one, since they check all possible factors of n - and if n is a prime number, this means trial factors all the way up to n. Thus, if the algorithm finds one factor only, n, it is proof that n is a prime. If more than one factor is found, then n is a composite integer. A more computationally advantageous way of saying this is, if any prime whose square does not exceed n divides it without a remainder, then n is not prime.

Speed

In the worst case, trial division is a laborious algorithm. For a base-2 n digit number a, if it starts from two and works up only to the square root of a, the algorithm requires

trial divisions, where denotes the prime-counting function, the number of primes less than x. This does not take into account the overhead of primality testing to obtain the prime numbers as candidate factors. A useful table need not be large: P(3512) = 32749, the last prime that fits into a sixteen-bit signed integer and P(6542) = 65521 for unsigned sixteen-bit integers. That would suffice to test primality for numbers up to 655372 = 4,295,098,369. Preparing such a table (usually via the Sieve of Eratosthenes) would only be worthwhile if many numbers were to be tested. If instead a variant is used without primality testing, but simply dividing by every odd number less than the square root the base-2 n digit number a, prime or not, it can take up to about:

In both cases the required time grows exponentially with the digits of the number.

Even so, this is a quite satisfactory method, considering that even the best known algorithms have exponential time growth. For a chosen uniformly at random from integers of a given length, there is a 50% chance that 2 is a factor of a, and a 33% chance that 3 is a factor of a, and so on. It can be shown that 88% of all positive integers have a factor under 100, and that 92% have a factor under 1000. Thus, when confronted by an arbitrary large a, it is worthwhile to check for divisibility by the small primes, since for , in base-2 .

However, many-digit numbers that do not have factors in the small primes can require days or months to factor with trial division. In such cases other methods are used such as the quadratic sieve and the general number field sieve (GNFS). Because these methods also have superpolynomial time growth a practical limit of n digits is reached very quickly. For this reason, in public key cryptography, values for a are chosen to have large prime factors of similar size so that they cannot be factored by any publicly known method in a useful time period on any available computer system or computer cluster such as supercomputers and computer grids. The largest cryptography-grade number that has been factored is RSA-768, using the GNFS and a network of hundreds of computers. The running time was approximately 2 years.

References

1. ^{{cite journal | last = Mollin | first = Richard A. | doi = 10.2307/3219180 | issue = 1 | journal = Mathematics Magazine | mr = 2107288 | pages = 18–29 | title = A brief history of factoring and primality testing B. C. (before computers) | volume = 75 | year = 2002}}
  • {{cite book | last=Childs | first=Lindsay N. | authorlink= | title=A concrete introduction to higher algebra | edition=3rd | series=Undergraduate Texts in Mathematics | location=New York, NY | publisher=Springer-Verlag | year=2009 | isbn=978-0-387-74527-5 | zbl=1165.00002 }}
  • {{cite book | last1=Crandall | first1=Richard | author1-link=Richard Crandall | last2=Pomerance | first2=Carl | author2-link=Carl Pomerance | title=Prime numbers. A computational perspective | edition=2nd | location=New York, NY | publisher=Springer-Verlag | year=2005 | isbn=0-387-25282-7 | zbl=1088.11001 }}

External links

  • Javascript Prime Factor Calculator using trial division. Can handle numbers up to about 9×1015
  • [https://www.blogcyberini.com/2018/04/algoritmo-fatoracao-de-numeros-inteiros-divisao-por-tentativa.html Trial Division in Java, C and JavaScript] {{pt icon}}
{{number theoretic algorithms}}

3 : Integer factorization algorithms|Division (mathematics)|Articles with example Python code

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/14 0:15:09