Home >Backend Development >PHP Tutorial >. Sum of Square Numbers
633. Sum of Square Numbers
Medium
Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.
Example 1:
Example 2:
Constraints:
Solution:
class Solution { /** * @param Integer $c * @return Boolean */ function judgeSquareSum($c) { for ($i = 2; $i * $i <= $c; $i++) { $count = 0; if ($c % $i == 0) { while ($c % $i == 0) { $count++; $c /= $i; } if ($i % 4 == 3 && $count % 2 != 0) return false; } } return $c % 4 != 3; } }
Contact Links
The above is the detailed content of . Sum of Square Numbers. For more information, please follow other related articles on the PHP Chinese website!