Algorithm to find the number of numbers which are both perfect square as well as perfect cube

1.3k Views Asked by At

I was teaching indices chapter to my brother when I got this idea to find the number of numbers which are perfect squares as well as perfect cubes. I was wondering whether there is an algorithm to find these numbers between a fixed range like between $0$ and $100$. One number that can be thought of belonging to this category is 64,it as the cube of 4 and square of 8.

2

There are 2 best solutions below

2
On BEST ANSWER

You do know that being a square and a cube is equivalent to being a sixth power, don't you? The number of sixth powers up to (and including) $n\ge 0$ is $1+\lfloor\sqrt[6]n\rfloor$, hence the number of sixth powers between $a$ and $b$, inclusive (with $0<a\le b$), is $\lfloor\sqrt[6] b\rfloor - \lfloor\sqrt[6] {a-1}\rfloor$

2
On

You can use some programming languages to find the solution given that the range is not so huge. I recommend sagemath, it is a PYTHON like opensource tool.

Another way you may want to construct these results: the sixth power of p: p^6 is both a cube and a square.