Check whether the number can be made perfect square after adding 1 | Python3 implementation of the approach ; Function that returns true if x is a perfect square ; Find floating po value of square root of x ; If square root is an eger ; Function that returns true if n is a sunny number ; If ( n + 1 ) is a perfect square ; Driver code
import math as mt NEW_LINE def isPerfectSquare ( x ) : NEW_LINE INDENT sr = mt . sqrt ( x ) NEW_LINE return ( ( sr - mt . floor ( sr ) ) == 0 ) NEW_LINE DEDENT def isSunnyNum ( n ) : NEW_LINE INDENT if ( isPerfectSquare ( n + 1 ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT n = 3 NEW_LINE if ( isSunnyNum ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT