Math Fundamentals18 sections · 814 units
Open in Course

Perfect Squares

Integers with integer roots

A perfect square is an integer that equals some integer squared. For example, 16=4216 = 4^2, so 16 is a perfect square. But 15 is not because 15\sqrt{15} is not an integer.

You can check if nn is a perfect square by computing n\sqrt{n} and checking if it's an integer. In code: take the floor of the square root, square it, and see if you get nn back.

Perfect squares appear in number theory problems, geometry (area calculations), and dynamic programming. Let me show you a problem that uses this concept.