10812 - Beat the Spread!
This is a pretty standard formula manipulation math problem.
Given the sum of a and b, and the difference of a and b, find a and b. First, make sure the difference is not greater than the sum, since this would imply one of them is negative. Without a lost of generality, assume . We get
Solving for a in terms of b, we get:
plugging it into the latter equation:
We then solve for b numerically and plug it into one of the formulas to get a. All that's left is to check that a and b are both non-negative, and we're done.
NOTE: Check that and are both divisible by 2. :-)
8 40 20 20 40 1 5 100 6 12 61 51 61 123 512 63 1
30 10 impossible impossible 53 47 impossible impossible impossible 32 31