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 ; 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 Code
< ? php function factorize ( $ n ) { $ count = 0 ; while ( ! ( $ n % 2 ) ) { $ n >>= 1 ; $ count ++ ; } if ( $ count ) echo ( 2 . " " ▁ . ▁ $ count ▁ . ▁ " " for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i += 2 ) { $ count = 0 ; while ( $ n % $ i == 0 ) { $ count ++ ; $ n = $ n / $ i ; } if ( $ count ) echo ( $ i . " ▁ " . $ count ) ; } if ( $ n > 2 ) echo ( $ n . " ▁ " . 1 ) ; } $ n = 1000000000000000000 ; factorize ( $ n ) ; ? >