Check if N can be expressed as product of 3 distinct numbers | C ++ 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
#include " bits / stdc + + . h " NEW_LINE using namespace std ; void getnumbers ( int n ) { vector < int > divisor ; for ( int i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { divisor . push_back ( i ) ; n /= i ; } } if ( n != 1 ) { divisor . push_back ( 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 [ i ] ; } else if ( b == 1 b == a ) { b = b * divisor [ i ] ; } else { c = c * divisor [ i ] ; } } if ( a == 1 b == 1 c == 1 a == b b == c a == c ) { cout << " - 1" << endl ; } else { cout << a << ' ▁ ' << b << ' ▁ ' << c << endl ; } } int main ( ) { int n = 64 ; getnumbers ( n ) ; }