Prime factors of a big number | C # program to print prime factors and their powers . ; 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
using System ; public class GFG { static void factorize ( long n ) { int count = 0 ; while ( ! ( n % 2 > 0 ) ) { n >>= 1 ; count ++ ; } if ( count > 0 ) Console . WriteLine ( "2" + " ▁ " + count ) ; for ( long i = 3 ; i <= ( long ) Math . Sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n = n / i ; } if ( count > 0 ) Console . WriteLine ( i + " ▁ " + count ) ; } if ( n > 2 ) Console . WriteLine ( n + " ▁ " + "1" ) ; } static public void Main ( ) { long n = 1000000000000000000 ; factorize ( n ) ; } }