I donot get the formula at the end how we derived it

For the last question about number of grids, how do i derive the said formula