from math import gcd from functools import cmp_to_key # 偏角ソート https://nebocco.hatenablog.com/entry/2021/11/13/185816 から拝借しています。 def area(p): x, y = p if y < 0: return 3 elif x < 0: return 2 else: return 1 def arg_cmp(p, q): ap = area(p) aq = area(q) if ap < aq: return -1 elif ap > aq: return 1 else: px, py = p qx, qy = q z = px * qy - py * qx if z > 0: return -1 elif z < 0: return 1 else: return 0 lst = [] MAX = 650 for x in range(1, MAX): for y in range(1, MAX): if gcd(x, y) != 1: continue for dx, dy in ((1, 1), (1, -1), (-1, 1), (-1, -1)): lst.append((x * dx, y * dy)) SIZE = 10 ** 6 cur_x = 0 cur_y = 0 print(SIZE) print(cur_x, cur_y) for x, y in sorted(lst, key=cmp_to_key(arg_cmp))[:SIZE - 1]: cur_x += x cur_y += y # assert -10 ** 9 <= cur_x <= 10 ** 9 # assert -10 ** 9 <= cur_y <= 10 ** 9 print(cur_x, cur_y)