Check whether N can be a Perfect Cube after adding or subtracting K | C ++ implementation of the above approach ; Function to check if a number is a perfect Cube or not ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPerfectCube ( int x ) { int cr = round ( cbrt ( x ) ) ; return ( cr * cr * cr == x ) ; } void canBePerfectCube ( int N , int K ) { if ( isPerfectCube ( N + K ) || isPerfectCube ( N - K ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; } int main ( ) { int N = 7 , K = 1 ; canBePerfectCube ( N , K ) ; N = 5 , K = 4 ; canBePerfectCube ( N , K ) ; N = 7 , K = 2 ; canBePerfectCube ( N , K ) ; return 0 ; }