Function to precompute the sum of perfect squares and store then in an array
function precomputation ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfect ( i ) ; } } var L = 6 , R = 28 ; precomputation ( ) ; document . write ( pref [ R ] - pref [ L - 1 ] ) ;