text: Find Cube Pairs | Set 1 ( A n ^ ( 2 / 3 ) Solution ) | C # program to find pairs that can represent the given number as sum of two cubes ; Function to find pairs that can represent the given number as sum of two cubes ; find cube root of n ; create an empty map ; Consider all pairs such with values less than cuberoot ; find sum of current pair ( x , y ) ; do nothing if sum is not equal to given number ; if sum is seen before , we found two pairs ; if sum is seen for the first time ; Driver code
code: using System ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void findPairs ( int n ) { int cubeRoot = ( int ) Math . Pow ( n , 1.0 / 3.0 ) ; Dictionary < int , pair > s = new Dictionary < int , pair > ( ) ; for ( int x = 1 ; x < cubeRoot ; x ++ ) { for ( int y = x + 1 ; y <= cubeRoot ; y ++ ) { int sum = x * x * x + y * y * y ; if ( sum != n ) continue ; if ( s . ContainsKey ( sum ) ) { Console . Write ( " ( " + s [ sum ] . first + " , ▁ " + s [ sum ] . second + " ) ▁ and ▁ ( " + x + " , ▁ " + y + " ) " + " STRNEWLINE " ) ; } else s . Add ( sum , new pair ( x , y ) ) ; } } } public static void Main ( String [ ] args ) { int n = 13832 ; findPairs ( n ) ; } }