Check if a number can be expressed as a product of exactly K prime divisors | Java implementation to Check if a number can be expressed as a product of exactly K prime divisors ; function to find K prime divisors ; count number of 2 s that divide N ; N must be odd at this point . So we can skip one element ; divide the value of N ; increment count ; Condition to handle the case when n is a prime number greater than 2 ; check if maximum_split is less than K then it not possible ; Driver code ; initialise N and K
class GFG { static void KPrimeDivisors ( int N , int K ) { int maximum_split = 0 ; while ( N % 2 == 0 ) { maximum_split ++ ; N /= 2 ; } for ( int i = 3 ; i * i <= N ; i = i + 2 ) { while ( N % i == 0 ) { N = N / i ; maximum_split ++ ; } } if ( N > 2 ) maximum_split ++ ; if ( maximum_split < K ) { System . out . println ( " No " ) ; return ; } System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { int N = 12 ; int K = 3 ; KPrimeDivisors ( N , K ) ; } }