Finding Pythagorean triples

Sure enough, it exists:

julia> function find_next_imperfect_square(n)
           while true
               root = √n
               if isinteger(root) && Int(root)^2 != n
                   return n
               end
               n += 1
           end
       end
find_next_imperfect_square (generic function with 1 method)

julia> n = find_next_imperfect_square(2^52)
4503599627370497

julia> root = √n
6.7108864e7

julia> isinteger(root)
true

julia> Int(root)^2
4503599627370496

julia> Int(root)^2 == n
false

So there’s the true bound: isinteger∘sqrt will work for all n < 4503599627370497. Didn’t take much time at all to find. Know what that number is? :slight_smile:

3 Likes