Check if a number can be represented as sum of two positive perfect cubes | C # program for the above approach ; Function to check if N can be represented as sum of two perfect cubes or not ; if it is same return true ; ; if the curr smaller than n increment the lo ; if the curr is greater than curr decrement the hi ; Driver Code ; Function call to check if N can be represented as sum of two perfect cubes or not
using System ; class GFG { static bool sumOfTwoCubes ( int n ) { int lo = 1 , hi = ( int ) Math . Pow ( n , ( 1.0 / 3.0 ) ) ; while ( lo <= hi ) { int curr = ( lo * lo * lo + hi * hi * hi ) ; if ( curr == n ) return true ; if ( curr < n ) lo ++ ; else hi -- ; } return false ; } public static void Main ( String [ ] args ) { int N = 28 ; if ( sumOfTwoCubes ( N ) ) { Console . Write ( " True " ) ; } else { Console . Write ( " False " ) ; } } }