p = prob (overnight born = boy| Next day chosen = boy)
= prob (overnight born = boy AND Next day chosen = boy) / prob (Next day chosen = boy)
= .5 * 4/T / (.5*4/T + .5 * 3/T) = 2/3.5 = 4/7 ~ .57

If two numbers are a, b, then the new number you are putting in the place of these two numbers is = ab + a + b = (a + 1)(b + 1) - 1 = c (say)
Now when you take c and d next, then the replacement number becomes = cd + c + d
= (c + 1)(d + 1) - 1
= (a + 1)(b + 1)(d + 1) - 1.
So final number remaining will be (1 + 1)(2 + 1)(3 + 1)....(39 + 1)(40 + 1) - 1 = 41! - 1.