from math import log10 sq2 = [(1, 1)] count = 0 for i in xrange(1, 1001): last = sq2[len(sq2) - 1] if int(log10(last[0])) > int(log10(last[1])): print last count += 1 sq2.append((last[0] + 2 * last[1], last[0] + last[1])) print count