Prime factors of a big number | function to calculate all the prime factors and count of every prime factor ; count the number of times 2 divides ; n = parseInt ( n / 2 ) equivalent to n = n / 2 ; ; if 2 divides it ; check for all the possible numbers that can divide it ; if n at the end is a prime number . ; driver program to test the above function
function factorize ( n ) { var count = 0 ; while ( ( n % 2 ) == 0 ) { count ++ ; } if ( count ) document . write ( 2 + " " + count + " " ) ; for ( var i = 3 ; i <= parseInt ( Math . sqrt ( n ) ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n = parseInt ( n / i ) ; } if ( count != 0 ) document . write ( i + " " + count + " " ) ; } if ( n > 2 ) document . write ( n + " " + 1 + " " ) ; } var n = 1000000000000000000 ; factorize ( n ) ;