If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, P(BB) = (15/21)×(14/20) = 1/2. The next such arrangement, for which there is exactly 50% chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs. By finding the first arrangement to contain over 1012 = 1,000,000,000,000 discs in total, determine the number of blue discs that the box would contain.
import datetime import math def MainProc1(y): dtStart = datetime.datetime.now() print ("Started at: ", dtStart) print ("y = ", y, " the power, log(y), is ", math.ceil(math.log(y, 10))) nCounter = 0 bSolution = False for j in range (y, y * 10, 1): nTemp = j * (j - 1) nTemp1 = math.floor(j/math.sqrt(2)) for i in range (nTemp1, (nTemp1 * 10), 1): nTemp2 = 2 * i * (i - 1) nCounter += 1 if nTemp == nTemp2 : print(j, i, nTemp2, nTemp) print("Solution !!") bSolution = True break elif nTemp < nTemp2 : break if bSolution == True: break dtEnd = datetime.datetime.now() print("The number of iterations are ", nCounter) print("Start time is ", dtStart.time(), " End time is ", dtEnd.time()) print ("Time span is %s"%(dtEnd-dtStart)) if bSolution == False : print("No solutions are found.") else : print("*** The solution is found. ***", j, i) ################# MainProc1(math.floor(math.pow(10, 12)))
$x=756872327473 \approx 10^{11.879}$ $y=1070379110497 \approx 10^{12.029}$