As said earlier, a natural number is a sum of two squares if and only if each prime factor that's 3 modulo 4 occurs to an even power in the number's prime factorization.

```
require 'prime'
def judge_square_sum(c)
c == 0 || c.prime_division.all? { |p, e| p % 4 != 3 || e.even? }
end
```