factor
Find prime factors of an integer
TLDR
Display the prime-factorization of a number
Take the input from stdin if no argument is specified
SYNOPSIS
factor [OPTION]... [NUMBER]...
If no NUMBER is given, read numbers from standard input.
PARAMETERS
--help
Display a help message and exit.
--version
Display version information and exit.
DESCRIPTION
The factor command in Linux is a simple yet powerful utility used to compute the prime factors of specified positive integers. It takes one or more numbers as arguments and outputs their prime factorization. For each number, it lists the number itself, followed by all its prime factors, repeating factors as many times as they divide the original number. For instance, `factor 12` would output `12: 2 2 3`. If no numbers are provided on the command line, factor will read numbers from standard input, one per line, making it versatile for scripting or processing lists of numbers. The command is part of the GNU Core Utilities, making it a standard tool available on most Linux distributions. While efficient for numbers that are products of relatively small primes or numbers within its practical limits (typically up to 2^63 - 1 on 64-bit systems), it's important to note that factoring very large numbers (especially those with large prime factors) can be computationally intensive and time-consuming, even for this utility. It serves as an excellent tool for basic number theory tasks and is widely used for educational purposes or quick checks of number properties.
CAVEATS
Factoring large numbers is a computationally intensive problem. While factor is optimized for common cases and numbers up to a typical 64-bit integer limit, it is not designed for cryptographic-grade factorization of extremely large numbers (e.g., hundreds of digits long). For such numbers, it might run indefinitely or fail to find factors within a reasonable timeframe. It primarily uses trial division and Pollard's rho algorithm for factorization.
EXAMPLES
1. Factor a single number:factor 100
Output: 100: 2 2 5 5
2. Factor multiple numbers:factor 17 36 1000
Output:17: 17
36: 2 2 3 3
1000: 2 2 2 5 5 5
3. Read numbers from standard input:echo -e "1234567890\n987654321" | factor
Output:1234567890: 2 3 5 7 11 13 37 101 9901
987654321: 3 3 17 379721
INPUT FORMAT
The command expects positive integers as input. If a negative number is provided, its absolute value will be factored. Non-integer inputs or inputs that exceed the system's maximum supported integer size (e.g., 2^63 - 1 on 64-bit systems) may result in errors or unexpected behavior.
HISTORY
The factor command is a standard utility included in the GNU Core Utilities package, which provides fundamental command-line tools for Unix-like operating systems. Its purpose has remained consistent: to provide a straightforward way for users to find the prime factors of integers, an essential operation in number theory and basic mathematics. Its development focuses on robustness and accessibility as a core system utility.