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 range(1, limit): for n in range(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): return b // 2 print(main(1300))