Count ways to represent a number as sum of perfect squares | ''Store perfect squares less than or equal to N ; ''Utility function to calculate perfect squares less than or equal to N ; ''Function to find the number of ways to represent a number as sum of perfect squares ; '' Handle the base cases ; '' Include the i-th index element ; '' Exclude the i-th index element ; '' Return the result ; ''Driver Code ; '' Given Input ; '' Precalculate perfect  squares <= N ; '' Function Call
psquare = [ ] NEW_LINE def calcPsquare ( N ) : NEW_LINE INDENT for i in range ( 1 , N ) : NEW_LINE INDENT if i * i > N : NEW_LINE INDENT break NEW_LINE DEDENT psquare . append ( i * i ) NEW_LINE DEDENT DEDENT def countWays ( index , target ) : NEW_LINE INDENT if ( target == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( index < 0 or target < 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT inc = countWays ( index , target - psquare [ index ] ) NEW_LINE exc = countWays ( index - 1 , target ) NEW_LINE return inc + exc NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 9 NEW_LINE calcPsquare ( N ) NEW_LINE print ( countWays ( len ( psquare ) - 1 , N ) ) NEW_LINE DEDENT