def test(x): sq = 12 * x + 1 ss = int(sq ** 0.5) if ss * ss != sq: return False if ss % 6 != 5: return False return True def main(limit): for d in xrange(1, limit): for n in xrange(5, limit): m = n + d a = 3 * (m * m + n * n) - m - n b = d * (3 * (m + n) - 1) if test(a) and test(b): print a / 2, b / 2, m, n return main(1300)