laymax = lambda x: (2 * x + 1) ** 2 def isp(x): if x == 2: return True if x <= 1 or x & 1 == 0: return False for i in xrange(3, int(x ** 0.5) + 1, 2): if x % i == 0: return False return True be = 3 non = 2 i = 2 while 9 * be >= non: tmp = laymax(i) for j in xrange(4): #print float(be) / (be + non) if isp(tmp): be += 1 else: non += 1 tmp -= 2 * i i += 1 print 2 * i - 1