Check if a number can be represented as product of two positive perfect cubes | C ++ program for the above approach ; Function to check if N can be represented as the product of two perfect cubes or not ; Stores the perfect cubes ; Traverse the Map ; Stores the first number ; Stores the second number ; Search the pair for the first number to obtain product N from the Map ; If N cannot be represented as the product of the two positive perfect cubes ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void productOfTwoPerfectCubes ( int N ) { map < int , int > cubes ; for ( int i = 1 ; i * i * i <= N ; i ++ ) cubes [ i * i * i ] = i ; for ( auto itr = cubes . begin ( ) ; itr != cubes . end ( ) ; itr ++ ) { int firstNumber = itr -> first ; if ( N % itr -> first == 0 ) { int secondNumber = N / itr -> first ; if ( cubes . find ( secondNumber ) != cubes . end ( ) ) { cout << " Yes " ; return ; } } } cout << " No " ; } int main ( ) { int N = 216 ; productOfTwoPerfectCubes ( N ) ; return 0 ; }