2. The digits $1,2,3,4,5, A$ and $B$ are all different and nonzero. Each of the two six-digit integers 'A12345' and ' $12345 A$ ' is divisible by $B$.
Find all possible pairs of values of $A$ and $B$.
Solution
Since the digits $1,2,3,4,5, A$ and $B$ are all different and nonzero, $A$ and $B$ must be two of 6,7 , 8 and 9 .

The integer ' $A 12345$ ' is odd and is divisible by $B$, so $B$ must be odd too. This means $B$ will either be 7 or 9 .

Suppose $B=7$. This means that ' $12345 A$ ' is divisible by 7 , but the only multiples of 7 starting with 12345 are 123452 and 123459 , which are $17636 \times 7$ and $17637 \times 7$, respectively. Since $A$ cannot be $2, A$ must be 9 .
We must now check that ' $A 12345$ ' is divisible by 7 and this is true since 912345 is $130335 \times 7$.
Suppose instead that $B=9$. This means that ' $12345 A$ ' is divisible by 9 , but the only multiple of 9 starting with 12345 is 123453 , which is $13717 \times 9$, and $A$ cannot be 3 , so $B$ cannot be 9 .
Therefore there is only one solution and that is $A=9, B=7$.