Check whether a number can be represented as difference of two consecutive cubes | Python3 program for the above approach ; Function to print the two consecutive numbers whose difference is N ; Iterate in the range [ 0 , 10 ^ 5 ] ; Function to check if N is a perfect cube ; Find floating povalue of square root of x . ; If square root is an integer ; Function to check whether a number can be represented as difference of two consecutive cubes ; Check if 12 * N - 3 is a perfect square or not ; Given number N
import math NEW_LINE def printt ( N ) : NEW_LINE INDENT for i in range ( 100000 ) : NEW_LINE INDENT if ( pow ( i + 1 , 3 ) - pow ( i , 3 ) == N ) : NEW_LINE INDENT print ( i , ' ' , i + 1 ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT def isPerfectSquare ( x ) : NEW_LINE INDENT sr = math . sqrt ( x ) NEW_LINE return ( ( sr - math . floor ( sr ) ) == 0 ) NEW_LINE DEDENT def diffCube ( N ) : NEW_LINE INDENT return isPerfectSquare ( 12 * N - 3 ) NEW_LINE DEDENT N = 19 NEW_LINE if ( diffCube ( N ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE printt ( N ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT