Take the square root of B and round it to whole numbers, giving one or two values of S.
Where S is odd, the answer is (S+P)². Where S is even, the answers are
(S+P+1)² and (S+P-1)². Every step below is worked with exact arithmetic,
so large numbers and decimals stay precise.