Presuming the stipulations I mentioned in my comment above (the two integers are distinct and we cannot have the same number on both hats): >! B gets it at the second question. B knows that his number is an addition of two of the factors of 4. This means the only possibilities are 4 and 5. Since we are assuming we can't have the same number on both hats, the only possibility is 5.