[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

## 25.1 `factor`

: Print prime factors

`factor`

prints prime factors. Synopses:

factor [ |

If no `number` is specified on the command line, `factor`

reads
numbers from standard input, delimited by newlines, tabs, or spaces.

The only options are ‘`--help`’ and ‘`--version`’. See section Common options.

The algorithm it uses is not very sophisticated, so for some inputs
`factor`

runs for a long time. The hardest numbers to factor are
the products of large primes. Factoring the product of the two largest 32-bit
prime numbers takes about 80 seconds of CPU time on a 1.6 GHz Athlon.

$ p=`echo '4294967279 * 4294967291'|bc` $ factor $p 18446743979220271189: 4294967279 4294967291 |

Similarly, it takes about 80 seconds for GNU factor (from coreutils-5.1.2) to “factor” the largest 64-bit prime:

$ factor 18446744073709551557 18446744073709551557: 18446744073709551557 |

In contrast, `factor`

factors the largest 64-bit number in just
over a tenth of a second:

$ factor `echo '2^64-1'|bc` 18446744073709551615: 3 5 17 257 641 65537 6700417 |

An exit status of zero indicates success, and a nonzero value indicates failure.