from math import isqrt

def solve(num, k):
    ans = []
    for a in range(num - 1, 1, -1):
        for nm in range(1, a):
            b2 = a * a - nm * nm
            b = isqrt(b2)
            if b * b == b2:                
                n, m = isqrt(a + b), isqrt(a - b)
                if n * n == a + b and m * m == a - b:
                    ans.append([a, b])
        if len(ans) >= k:
            break
    return ans[:k]
print(solve(1000, 4))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: