# How to find the number of perfect cubes in a range

Can we find the number of perfect cubes in a range.

For eg if L = 7 and R = 220 then count will be 5 because 8, 27, 64, 125, 216 are the perfect squares in

the range L to R. Can we make a formula for this?

I am assuming $$L\leq R$$, and we include $$L$$ and $$R$$ themselves in the range. Take the cube roots of $$L$$ and $$R$$. Round $$\sqrt[3]L$$ up and $$\sqrt[3]R$$ down. Take their difference, and add $$1$$, and you're done. In symbols: $$\left\lfloor \sqrt[3]R\right\rfloor - \left\lceil\sqrt[3]L\right\rceil + 1$$ (Changing whether $$L$$ and $$R$$ themselves count, should they happen to be cubes, will change whether we round up or down, and exactly which number we add at the end. For instance, if $$R$$ counts, but $$L$$ does not, then we round them both down, and do not add anything at the end.)
To see how this formula works, let's take your example numbers. Then $$\sqrt[3]L \approx 1.9$$. Rounding this up gives the lowest number whose cube is above $$L$$, namely $$2$$ (as $$2^3$$ is large enough, but $$1^3$$ isn't).
We also have $$\sqrt[3]{R}\approx 6.04$$. Rounding this down gives the largest number whose cube is below $$R$$, namely $$6$$ (as $$6^3$$ is small enough, but $$7^3$$ is too large).
So all the integers from $$2$$ to $$6$$ have cubes in our range, and no other integers do. And from $$2$$ to $$6$$ there are $$6-2 + 1 = 5$$ integers.
$$\lfloor \sqrt[3]{R} \rfloor - \lceil \sqrt[3]{L} \rceil + 1 = \lfloor \sqrt[3]{220} \rfloor - \lceil \sqrt[3]{7} \rceil + 1 =6-2+1=5$$