Sunday, 11 March 2012

Finding Prime Factors Of A Number From Linux Terminal

Linux is awesome because of its powerful commanline interface from where you can do any tasks of varied complexities. I've been posting different command line tricks for system administrations & stuffs like that. But this time I am posting a little command line trick to find the prime factors of any number.

Linux provides a command factor that lets you find the prime factors of any number. So if you are into mathematics and working on prime factorizations, why worry? Just open the terminal and use the factor command.

This command takes any number of integer values as the argument and prints the prime factor of each of them. If no number is specified, it takes the value from standard input.

samar@Techgaun:~$ factor 2056 1234567

More information on factor command: The factor command makes use of the Pollard Rho algorithm which is suitable for numbers with relatively small factors. It is not quite good for computing factors of large numbers whose factors are not small values.