3

I got this question as a programming exercise. I first thought it was rather trivial, and that $m = 5n$ because the number of trailing zeroes are given by the number of factors of 5 in $m!$ (and factors of 2, but there are always a lot more of those).

But it seems like this is not true, because I'm not getting the correct answers for certain $n$. Any hints?

naslundx
  • 9,720

1 Answers1

4

The answer lies in the very interesting observation made in this post: How come the number $N!$ can terminate in exactly $1,2,3,4,$ or $6$ zeroes but never $5$ zeroes?

Basically, for some n there's just no solution, unless you read "ends with n zeros" as "ends with at least n zeros", but computers don't do that.

  • 1
    Computers try to do what you tell them to do. If you genuinely program it to look for a number that ends with exactly 5 zeroes, it will either tell you there's no such number or it will get stuck in an infinite loop. But if the human programming the computer does not fully understand the problem, his program will probably be faulty. – James47 Aug 05 '14 at 22:29
  • Although with factorials I suspect the program would crash far more quickly than with other failures to recognize a point beyond which no answer can exist. – Robert Soupe Aug 06 '14 at 04:05