Given two integers a, b, we want n such that n*(n+1) = 4*(b-a)-1
(Pascal Triangle formula)
In addition, when the range (a to b) is odd, we actually have n^2 = 4*(b-a)-1 because of the extra n.
Thus, we can get n = floor( sqrt( 4*(b-a)-1 ) )].
Note that we can also apply the same sqrt function for even ranges:
since n*(n+1) = 4*(b-a)-1
n <= sqrt( 4*(b-a)-1[/b] ) <= n+1
( we can use floor!
![:D](./images/smilies/icon_biggrin.gif)
thus for both even and odd ranges, n = floor( sqrt( 4*(b-a)-1 ) )
*special case: (b-a) == 0
Hope this helps
![:D](./images/smilies/icon_biggrin.gif)