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
using System ; using System . Collections . Generic ; class GFG { static void productOfTwoPerfectCubes ( int N ) { Dictionary < int , int > cubes = new Dictionary < int , int > ( ) ; for ( int i = 1 ; i * i * i <= N ; i ++ ) { cubes . Add ( i * i * i , i ) ; } foreach ( KeyValuePair < int , int > kvp in cubes ) { int firstNumber = kvp . Key ; if ( N % kvp . Key == 0 ) { int secondNumber = N / kvp . Key ; if ( cubes . ContainsKey ( secondNumber ) ) { Console . Write ( " Yes " ) ; return ; } } } Console . Write ( " No " ) ; } public static void Main ( ) { int N = 216 ; productOfTwoPerfectCubes ( N ) ; } }