this one is relatively straight forward with this type of problems. I just spent an evening and more to solve a similar but much more complicated problem:
2 numbers a and b, a >=b, both integers between 2 and 99. Mr. P knows the sum S=a+b, and Mr. Q knows the product M=a*b. Here is the conversation:
Q: I don't know what are a and b.
P: I know you don't know, and I don't know either.
Q: I know now.
P: I also know now.
What are a and b?
That's a tough one. I'll take your word for it that there is a solution. I tried to brute force it by writing a simple python script to output every possible answer of S and M (pun not intended) leaving out only the obvious ones such as a=b=2 or M being a prime number. I looked at the results and I think I see many values that could meet the conversation without either figuring out the answer. Such as:
S=10:
P would know that (a,b) = (5, 5) or (6, 4) or (7, 3) or (8, 2)
P would also know that M = 25 or 24 or 21 or 16
All of those values for M have more than one possible value of (a,b).
This is the same of you start with S = 11 or S=12.
I don't get how Q knows the answer just by knowing that P doesn't know and knows he doesn't know. It seems like that leaves a ton of possibilities.
I have to think about it more.
By the way this is the python script:
import os, sys, math
def is_prime(num):
if num > 2 and num % 2 == 0:
return False
for n in range(3, int(math.sqrt(num)) + 1, 2):
if num % n == 0:
return False
return True
results = "";
for a in range(2,100,1):
for b in range(2,100,1):
if b <= a and (a+b) > 5 and (a*b) > 8 and not is_prime(a*b):
results += "a={}, b={}, S={}, M={}\n".format(a, b, a+b, a*b);
f = open("s_and_m.txt","w");
f.write(results)
f.close()
EDIT: I just realized that 25 doesn't have more than one a,b pair. I'm going to figure this out.