Check if N can be expressed as product of 3 distinct numbers | Java program to find the three numbers ; function to find 3 distinct number with given product ; Declare a vector to store divisors ; store all divisors of number in array ; store all the occurence of divisors ; check if n is not equals to - 1 then n is also a prime factor ; Initialize the variables with 1 ; check for first number a ; check for second number b ; check for third number c ; check for all unwanted condition ; Driver function
import java . util . * ; class GFG { static void getnumbers ( int n ) { Vector < Integer > divisor = new Vector < Integer > ( ) ; for ( int i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { divisor . add ( i ) ; n /= i ; } } if ( n != 1 ) { divisor . add ( n ) ; } int a , b , c , size ; a = b = c = 1 ; size = divisor . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( a == 1 ) { a = a * divisor . get ( i ) ; } else if ( b == 1 b == a ) { b = b * divisor . get ( i ) ; } else { c = c * divisor . get ( i ) ; } } if ( a == 1 b == 1 c == 1 a == b b == c a == c ) { System . out . print ( " - 1" + "NEW_LINE"); } else { System . out . print ( a + " ▁ " + b + " ▁ " + c + "NEW_LINE"); } } public static void main ( String [ ] args ) { int n = 64 ; getnumbers ( n ) ; } }