text: 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
code: using System . IO ; using System ; using System . Collections ; class GFG { static ArrayList psquare = new ArrayList ( ) ; static void calcPsquare ( int N ) { for ( int i = 1 ; i * i <= N ; i ++ ) psquare . Add ( i * i ) ; } static int countWays ( int index , int target ) { if ( target == 0 ) return 1 ; if ( index < 0 target < 0 ) return 0 ; int inc = countWays ( index , target - ( int ) psquare [ index ] ) ; int exc = countWays ( index - 1 , target ) ; return inc + exc ; } static void Main ( ) { int N = 9 ; calcPsquare ( N ) ; Console . WriteLine ( countWays ( psquare . Count - 1 , N ) ) ; } }