;Task:
Solve the "<i>Impossible Puzzle</i>":

{{quote|
X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in this paragraph.

The following conversation occurs:

* S says "P does not know X and Y."
* P says "Now I know X and Y."
* S says "Now I also know X and Y!"

What are X and Y?
}}

{{task heading|Guidance}}

It can be hard to wrap one's head around what the three lines of dialog between S (the "sum guy") and P (the "product guy") convey about the values of X and Y.<br>
So for your convenience, here's a break-down:

{| class="wikitable"
|-
! 
! Quote
! Implied fact
|-
! 1) 
| S says "P does not know X and Y."
| For every possible sum decomposition of the number <tt>X+Y</tt>, the product has in turn ''more than one'' product decomposition.
|-
! 2)
| P says "Now I know X and Y."
| The number <tt>X*Y</tt> has ''only one'' product decomposition for which fact 1 is true.
|-
! 3)
| S says "Now I also know X and Y."
| The number <tt>X+Y</tt> has ''only one'' sum decomposition for which fact 2 is true.
|}

Terminology:
* ''"sum decomposition" of a number'' = Any pair of positive integers <tt>(A, B)</tt> so that <tt>A+B</tt> equals the number. Here, with the additional constraint <tt>2 ≤ A < B</tt>.
* ''"product decomposition" of a number'' = Any pair of positive integers <tt>(A, B)</tt> so that <tt>A*B</tt> equals the number. Here, with the additional constraint <tt>2 ≤ A < B</tt>.
<br>

Your program can solve the puzzle by considering all possible pairs <tt>(X, Y)</tt> in the range <tt>2 ≤ X < Y ≤ 98</tt>, and then successively eliminating candidates based on the three facts. It turns out only one solution remains!<br>
See the [[#Python|Python example]] for an implementation that uses this approach with a few optimizations.

{{task heading|See also}}

* &nbsp; Wikipedia: &nbsp; [[wp:Sum and Product Puzzle|Sum and Product Puzzle]]
<hr>

