Function to precompute the sum of perfect squares and store then in an array
void precomputation ( ) { for ( int i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfect ( i ) ; } } int main ( ) { int L = 6 , R = 28 ; precomputation ( ) ; cout << pref [ R ] - pref [ L - 1 ] ; return 0 ; }