TITLE: What is the smallest possible number
QUESTION [8 upvotes]: I spent an hour on this problem, but have no clue how to solve the it. Could anyone help me?
The problem ---- The numbers from 1 through 8 are separated into two sets, A and B. The numbers in A are multiplied together to get a. The numbers in B are multiplied together to get b. The larger of the two numbers a and b is written down. What is the smallest possible number that can be written down using this procedure?

REPLY [9 votes]: First note that the optimal values for $a$ and $b$ will both be even: otherwise, if say $a$ is odd then it will be at most $1\cdot3\cdot5\cdot 7 = 105$, so that $b-a \ge 279$ which we shall soon see is not optimal.
When $a$ and $b$ have the same parity, the factorization $8! = a\cdot b$ corresponds uniquely to a difference of squares
$$8! = \left(\frac{a+b}2\right)^2 - \left(\frac{a-b}2\right)^2.$$
Thus we can simply look for the smallest integer $y$ satisfying $8! = x^2-y^2$.  Noting that $x$ increases along with $y$, we can just try successive values of $x$, starting with the smallest conceivable value $201$ (any smaller and we'd have $x^2 < 8!$):
$$(201)^2 - 8! = 81 = 9^2.$$
Oh look, we already have a solution!  So $(a-b)/2 = 9$ and $(a+b)/2 = 201$, so $a = 210$ and $b=192$.  This is a very old (and now fairly obsolete) factoring technique known as Fermat factorization.  It happened to work splendidly well in this case, but usually it takes more trial and error.  For small numbers like $40320$ it's not a bad way to find the two factors that are closest together.
We still need to check that $210$ (or $192$) can be factored into some combination of numbers from $\{1,2,\ldots,8\}$: we might have had some bad luck if, we are forced to split the factor $6$ into $2\cdot 3$ because there's no other way to get $210$, in which case we'd have to look for the next value of $x$ and $y$.  But happily, $210 = 2\cdot3\cdot5\cdot7$ and the complementary factors $1\cdot4\cdot6\cdot 8$ obviously yield $192$, so the first value of $x$ and $y$ worked out.