From c06aae3acf8723c52ff65870d30ad73554551d0d Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Tue, 17 Nov 2026 03:47:37 -0800 Subject: [PATCH] fix(maths): use math.isqrt in perfect_square instead of float sqrt math.sqrt(num) * math.sqrt(num) == num reports many non-squares as squares (11, 14, 17, ...), misses squares above 2**53 and raises ValueError for negative input. Compare the exact integer square root instead. --- maths/perfect_square.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/perfect_square.py b/maths/perfect_square.py index 107e68528068..e77711c2fb26 100644 --- a/maths/perfect_square.py +++ b/maths/perfect_square.py @@ -18,7 +18,7 @@ def perfect_square(num: int) -> bool: >>> perfect_square(10) False """ - return math.sqrt(num) * math.sqrt(num) == num + return num >= 0 and math.isqrt(num) ** 2 == num def perfect_square_binary_search(n: int) -> bool: