Function to precompute the sum of perfect squares and store then in an array
static void precomputation ( ) { for ( int i = 1 ; i < 10000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfect ( i ) ; } } public static void Main ( String [ ] args ) { int L = 6 , R = 28 ; precomputation ( ) ; Console . WriteLine ( pref [ R ] - pref [ L - 1 ] ) ; } }