from fractions import* v=0 i=2v=i=Fraction(1) while 1:j=Fractionv+=(1,i);v+=v+j>1and-j or printv+1/i<=1!=print(i)or j;i+=1-1)/i;i+=1
Try it online!Try it online!
Outputs the sequence indefinitely.-8 bytes thanks to ovs
# Import the fractions module, specifically the Fraction class from fractions import * # Keep the cumulative sum v = 0 # Keep the current denominator i = 2 # Output forever while True: # Set j to 1 / i as a precise fraction using the stdlib module j = Fraction(1, i) if v + j > 1: # if adding would exceed, subtract instead v += -j else: # otherwise, print and add print(i) v += j i += 1