# Alice, Bob and Charlie know the sum, product and the difference between two numbers

This was sent to me by a friend so I can't source it but here's the full text:

Three Mathematics students, Alice, Bob and Charlie have to find the values of $$x$$ and $$y$$, with $$x, y \in \mathbb Z, 1 \leq x,y\leq 1000$$. Alice is told the product $$x \times y$$, Bob is told the sum $$x+y$$ and Charlie the difference $$| x-y |$$. Afterwards, the three have the following conversation:

Alice: I do not know the numbers.
Alice: Oh! Now I know them.
Bob: Now I know them too.
Charlie: I do not know the numbers. But I can guess one number, that is probably one of $$x,y$$, but I don't know for sure.
Alice: I can tell the number you're guessing, but it's not one of them.
Charlie: Then I have figured them out now.

What are the numbers?

I've been trying to figure this out the whole day but I can't even get to Charlie's part.

• I have seen this before... I can't remember where – or the answer ;) May 18 '20 at 18:05
• @WeatherVane, might have been here. This can be starting point to solve the puzzle as well qbyte.org/puzzles/p003s.html May 18 '20 at 18:14
• puzzling.stackexchange.com/questions/1968/… this is deleted question by @Deusovi because of plagiarism 3 years ago. so not sure it is going to be deleted again :) well only some reputable people can access to it I guess?
– Oray
May 18 '20 at 19:11
• @Deusovi knows the actual source of the question, maybe that deleted question could be revived. I dont know why it is deleted in the first place. even if it is a question without a reference, a reference could be added to the question instead of deletion.
– Oray
May 18 '20 at 19:23
• @WilliamPennanti Because one of them always lies, one always tells the truth, and one waffles. May 18 '20 at 21:40

I wrote a program to solve this. I do not know whether it is possible to get there without.

(1) Alice does not know: the product cannot be factored uniquely into numbers $$\le1000$$. This is more complicated as just counting prime factors, as, e.g., $$1,000,000$$ can be uniquely factorized $$=1000\cdot 1000$$.

(2) Bob knows this: no matter how his sum is split, the resulting product is of type (1)

(3) Now Alice knows: there is exactly one way to factor her product such that the resulting sum is of type (2). These gives 25,985 pairs according to my program.

(4) Now Bob knows: within these pairs satisfying (3) there is exactly one with his sum. Still 34 pairs are valid.

Now Charlie comes into play: to guess like he does, in these pairs there must be combinations with the same difference and where one number appears more than once. This is satisfied for the pairs $$(23,32)$$, $$(32,41)$$, $$(64,73)$$, all with difference 9. So Charlie would guess $$32$$, which is not one of $$x,y$$ as of Alice's remark. So the solution is $$x=64$$ and $$y=73$$.

• I was hoping for an elegant solution that doesn't require writing a program but your solution matches mine so I'll accept it. Nice! May 19 '20 at 15:51
• Would you mind sharing your script? May 19 '20 at 22:19
• @msh210 Here's mine in Haskell that gets the same answer: gist.github.com/LukaHorvat/d8aa733fee3da7ab5ac08817e4203ca7 May 21 '20 at 12:56

So I'm gonna go through it line by line and will edit and update each time I figure out a line. I'm also going to define variables: x+y=s; x*y=p; |x-y|=d

• Alice: I do not know the numbers.

p can't be prime. Otherwise (x,y)=(1,p), so Alice would know.

• Bob: I already knew that.

s-1 can't be prime. If s-1 was prime, than it would be possible that (x,y)=(1,s-1) which means Bob can't definatively state this.

• Alice: Oh! Now I know them.

p can have several factor pairs. However, only one factor pair is such that a+b isn't 1+prime. For example 6 won't work as 2*3=6 and 1*6=6; 2+3=5 and 1+6=7, which are two numbers not 1+prime. This means Alice won't know if it is (1,6) or (2,3). Currently am running a computer program to get a list of such possible pairs.

• Bob: Now I know them too.

This doesn't help us at all. This is because Bob can make a list of possible pairs after Alice's 2nd statement and add the numbers of each pair and compare them to the sum which he knows. It just confirms Bob didn't know the pair before, ruling out the options (1,1) and (1,2) which were already ruled out anyway.

• Charlie: I do not know the numbers. But I can guess one number, that is probably either x or y, but I don't know for sure.

He doesn't know what the numbers are. That means that the absolute difference of every pair in the list of possibilities can't be unique, so we can eliminate the pairs that they. There will be at least one pair in which x = y of a different pair for which |y-x| will be the same in both pairs.

• Alice: I can tell the number you're guessing, but it's not one of them.

The "at least one pair in which x = y of a different pair" is not one of the numbers so we can look at the other pair of that difference.

• Charlie: Then I have figured them out now.

• For Alice, I think you need to account for the situation when rot13(c vf n cebqhpg bs gjb qvssrerag cevzrf. Nyvpr pna snpgbevmr c naq vs vg'f fhpu n cebqhpg, vg'f pyrne jung gur ahzoref jrer). May 19 '20 at 9:22
• @Ramilles rot13( yrg'f fnl gur ahzore A'f cevzr snpgbevmngvba vf c1*c2. Ohg fgvyy, vg pna or snpgbevmrq va na nqqvgvbany jnl, 1*A. May 19 '20 at 10:10
• @Prim3numbah: That's true. However rot13(vs A > 999, gura jr pna or fher gung gur gjb ahzoref ner c1 naq c2.) This kind of "boundary effect" is very annoying and I guess I won't be solving this because of that... May 19 '20 at 11:00