Check whether the number can be made perfect square after adding 1 | C ++ implementation of the approach ; Function that returns true if x is a perfect square ; Find floating point value of square root of x ; If square root is an integer ; Function that returns true if n is a sunny number ; If ( n + 1 ) is a perfect square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPerfectSquare ( long double x ) { long double sr = sqrt ( x ) ; return ( ( sr - floor ( sr ) ) == 0 ) ; } bool isSunnyNum ( int n ) { if ( isPerfectSquare ( n + 1 ) ) return true ; return false ; } int main ( ) { int n = 3 ; if ( isSunnyNum ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }