In mathematics, prime factorization is the process of breaking down a complex number into a set of prime numbers that, when multiplied together, equal the original number. While this can be a tedious process to calculate manually on paper, Linux includes a built-in command line utility called factor that can instantly calculate and print the prime factors of virtually any number.
How to Use the factor Command
The factor command is incredibly straightforward. You simply type the command followed by the number you want to analyze.
- Open your Linux terminal.
- To find the prime factors of the number 100, type the following:
factor 100
Press Enter. The terminal will instantly output:
100: 2 2 5 5
This tells you that 2 × 2 × 5 × 5 equals 100, and all of those resulting numbers are primes.
Factoring Multiple Numbers
You are not limited to checking one number at a time. If you need to analyze a list of numbers, simply string them together in a single command, separated by spaces.
factor 15 21 33 42
The output will clearly list each number and its corresponding factors on separate lines:
15: 3 521: 3 733: 3 1142: 2 3 7
Factoring Massive Numbers
The true power of the factor utility is its speed when dealing with exceptionally large numbers. Finding the prime factors of a 10-digit number manually could take hours. In Linux, it takes milliseconds.
For example, try typing:
factor 1234567890
The terminal will instantly spit out the correct prime breakdown: 2 3 3 5 3607 3803.
If you accidentally type a number that is already a prime number (for example, 17), the command will simply return the number itself, indicating that it cannot be broken down any further (e.g., 17: 17).