How many six-digit numbers are there where the third digit is equal to the second last digit, …

combinatoricscontest-math

How many six-digit numbers are there where the third digit is equal to the second last digit, the digit in the ten-thousands place is equal to the digit in the hundreds place, and the product of all the digits is equal to the square of a natural number?

Attempt:

We are looking for numbers of the form $abc bcf$, where $ab^2c^2f=n^2$ for some $n \in \mathbb{N}$. This means that $af = m^2$ for some $m \in \mathbb{N}$. Now, I have separated it into three cases:

  1. Case: $a = f$, there are $10^3$ such numbers,
  2. Case: $a = x^2$ and $f = y^2$ and $a \neq f$, there are $10^2 \cdot 6$ such numbers,
  3. Case: $a = 2$ and $f = 8$ or $f = 2$ and $a = 8$, there are $2 \cdot 10^2$ such numbers.

Thus, I found that there are 1800 such numbers (but the solutions state 1458). Where did I go wrong?

Thank you in advance for your help.

Note: $0$ is not a natural number here.

Best Answer

If, as indicated in the edit, $0$ is not a natural number, that means the product of digits can't be zero and there are only $9$ possibilities for each digit. Consequently every $10$ in your calculation should be a $9$. This leads to an answer of $1377$.

A quick python script confirms that there are exactly $1377$ integers with this property, so the answer you were given is wrong. (The largest possible product of digits is $9^6=729^2$.)

squares=[n*n for n in range(1,730)]
r=0
for n in range(100000,1000000):
    x=str(n)
    y=1
    for z in x:
        y*=int(z)
    if y in squares and x[1]==x[3] and x[2]==x[4]:
        r+=1
print(r)

Incidentally, if $0$ is treated as a natural number, the answer is not $2600$, despite two previous posts. This is because numbers where $af$ is not a square but $b$ or $c$ is $0$ still give a square product. There are $19$ choices for $b,c$ with at least one $0$. There are $90$ overall possibilities for $a,f$ and of these $26$ have $af$ being a square (nine with $a=f$, nine with $f=0$, six combinations of $1,4,9$ and two of $2,8$) so there are $19\times 64=1216$ cases missing from the other answers, giving a total of $3816$.