from math import gcd from functools import cmp_to_key a=[] for i in range(1,1300): for j in range(1,1300): if gcd(i,j)==1: a.append((i,j)) def get_frac(tuple1): return tuple1[1]/tuple1[0] a.sort(key=get_frac) currx=0 curry=0 print(10**6) print(currx,curry) for i in range(10**6-1): currx+=a[i][0] curry+=a[i][1] print(currx,curry)