8

Since there are less powers of $5$ than of $2$ and since $10 = 2 \cdot 5$, I counted the number of zeros in $2017!$: $\left \lfloor{ \frac{2017}{5^1}}\right \rfloor + \left \lfloor{ \frac{2017}{5^2}}\right \rfloor +\left \lfloor{ \frac{2017}{5^3}}\right \rfloor +\left \lfloor{ \frac{2017}{5^4}}\right \rfloor = 502$

Now I need to find $\frac{2017!}{10^{502}} \pmod{10^5}$

Using Chinese remainder theorem I split the $\pmod{10^5}$ into $\pmod{2^5}$ and $\pmod{5^5}$. Since there are a lot more powers of $2$ left, $\frac{2017!}{10^{502}}\equiv 0 \pmod{2^5}$

I am having trouble with getting $\frac{2017!}{10^{502}} \pmod{5^5}$. What would be the best way to compute it?

Clarification: significant digits - the ones that follow up before the zeros at the right side of the number.

Zyberg
  • 381
  • Can you find the same thing mod 5? Start from the simple. – Kenny Lau Jun 27 '16 at 13:09
  • 1
    Hint: $1\times2\times3\times4\times6\times7\times8\times9\equiv1\mbox{ (mod 5)}$ – Kenny Lau Jun 27 '16 at 13:10
  • What do you mean by "last 5 significant digits"? Do you mean digits prior to whatever number of trailing zeros are in the number? – MPW Jun 27 '16 at 13:14
  • I'm not clear what "last 5 significant digits" should mean. Possibly it means the least significant nonzero digits, or possibly the leading five digits? – hardmath Jun 27 '16 at 13:15
  • @KennyLau, from your hint I see that $11 \times 12 \times 13 \times 14 \times 16 \times 17 \times 18 \times 9 \equiv 1 \pmod{5}$ as well, so:

    $\frac{2017!}{5^{502}} = \frac{2010! \times 2011 \times 2012 \times 2013 \times 2014 \times 2016 \times 2017}{5^{502}} \equiv \frac {2011 \times 2012 \times 2013 \times 2014\times 2016 \times 2017}{5^502} \equiv \frac{3}{5^{502}} \pmod{5}$ However, that's nothing near it...

    – Zyberg Jun 27 '16 at 13:19
  • 2
    @MPW, it means last non zero digits. – Zyberg Jun 27 '16 at 13:19
  • No, $\dfrac{2017!}{5^{502}}\equiv3\mbox{ (mod 5)}$, which is still wrong, because you forgot to factor in the fact that $\dfrac{10}5\ne1$. – Kenny Lau Jun 27 '16 at 13:20
  • Oh, I see, I made a mistake getting rid of 2010!. $\frac{2017!}{10^{502}} \equiv 2011 * 2012 * 2013 * 2014 * 2016 * 2017 \equiv 3 \pmod{5}$ Is it right now, @KennyLau? – Zyberg Jun 27 '16 at 13:24
  • 2
    Related: http://math.stackexchange.com/questions/130352/last-non-zero-digit-of-a-factorial also http://www.campusgate.co.in/2013/10/finding-right-most-non-zero-digit-of.html and http://www.mathpages.com/home/kmath489.htm and http://mathforum.org/library/drmath/view/71768.html – Gerry Myerson Jun 27 '16 at 13:28
  • So if the number is $\cdots 7009000012010000000\cdots0$, would you say "$01201$" or "$79121$"? – MPW Jun 27 '16 at 13:28
  • @MPW, it would be "01201". Although, with factorials there wouldn't be zeros apart from the ending of the number. – Zyberg Jun 27 '16 at 13:29
  • Also https://brilliant.org/discussions/thread/develop-an-algorithm-to-find-the-last-five-non-zer/ – Gerry Myerson Jun 27 '16 at 13:34
  • @Zyberg: I'll point out that the digits "$01201$" are not nonzero digits. But I wasn't aware that embedded zeroes can't occur, so in that case they're the same thing. Thanks for the clarification. – MPW Jun 27 '16 at 13:36
  • Even thought all the links that Gerry Myerson provided were very good, they were about only 1 last significant digit. I couldn't make any formulas come true for 5 last digits. – Zyberg Jun 28 '16 at 07:32
  • I would just like to point out that 2017! is small enough for any pc to compute in a fraction of a second. The number fits on 2 pages, and 15968 is the right answer. – Daan Michiels Jul 29 '16 at 17:19
  • I'm pretty sure that's not the number of zeros in $2017!$. It is the number of trailing zeros, but I'd consider it very surprising if there were no other zeros in that number. – celtschk Jul 31 '16 at 10:20

3 Answers3

3

OK, for what it's worth, the answer can be derived by casting out all factors of $5$ and multiplying the resulting numbers incrementally $\bmod 100000$, which also allows us to also divide out from the running product the same power of $2$ as the power of $5$ that we just cast out.

As a way of checking any more elegant mathematical approach, therefore, the result is

$15968$



As an aside, I'll share the process I used to calculate this and justify a shortcut that I used.

The basic idea here was to multiply successive numbers into a running product, excluding powers of $5$ and adjusting powers of $2$. The process for each number was:

  • find the highest power of $5$ that divides the new number
  • divide that out of the number
  • multiply the adjusted number into the running product and divide by an equivalent power of $2$
  • find the residue $\bmod 100000$

Note that this gives identical running $\bmod 100000$ values to @skyking's approach.

There is a intermittent problem with this approach, in that the running product will potentially be wrong for a couple of numbers after a large power of $5$ is divided out. Effectively, the value should be saturated with factors of $2$ from $8!$ onwards, but dividing out a suitable power of two may disturb this briefly. For example, the value for $15!$ is out in this process - $24368$ instead of the correct value, $74368$. Nevertheless, once a suitable number of factors of two in subsequent numbers are multiplied back into the product, the $\bmod 100000$ value gets back on track.

$2017$, occurring as it does directly after $2016$ = $2^5\cdot 63$, has an accurate running product by this method.

An continuously accurate running value can be produced, if necessary, by building up a "reserve" of a few powers of $2$ separately from a running product calculation, by stripping out powers of two from the successive values until the reserve is full. This is then used to compensate for powers of $5$ encountered, and multiplying these back in to the reduced running product. This correct gives the value for $15$ etc.

Joffan
  • 39,627
1

It's quite straight forward to calculate (and you don't have to figure out the number of trailing zeroes ahead of calculations). One could of course compute $2017!$ and take the last five significant digits.

However one could simplify the calculation by dividing away trailing zeroes and only keep the lower significant digits, but in doing so one have to take some care not to loose significant digits. Better way is to note that every time we get a zero at the end is because of a factor two and five and drop these factors pairwise. So we simply can for example defer the factors two and five and then at the end drop them pairwise and only keeping the factors two that are left.

To illustrate, after five steps we have:

$$1\times2\times3\times4\times5 = 24\times 5^1$$

here the last $5^1$ is to keep in mind the number of factors five we have to handle in the end.

$$24\times5^1\times6\times7\times8\times9\times10=36288\times2^1\times5^2$$

the next step is:

$$36288\times2^1\times5^2\times11=399168\times2^1\times5^2$$

now $399168>99999$ so we take modulo $100000$ and get to get $99168\times2^1\times5^2$ and continues...

skyking
  • 16,654
  • Wait, what? You did all 2017 calculations?!?!?! – fleablood Jul 28 '16 at 23:54
  • When we reduce mod 100000 and later divide by 10, how can we know the reduction didn't lose significant information? – Christian Sievers Jul 28 '16 at 23:59
  • @fleablood Yes, I did - you can easily do that by writing a python program for it... – skyking Jul 31 '16 at 10:03
  • @ChristianSievers You're absolutely right - I have modified the algorithm to take care of that problem. It's quite similar to Joffans answer and maybe his description is a bit simplier. – skyking Jul 31 '16 at 10:17
-1

I know how to do the last 3 significant digits, if that helps.

$4! = 24\\ \frac {9!}{5!} = 3024 \equiv 24\pmod {1000}$

$\frac {5n!}{5^n n!} = 24^n \pmod {1000}$

$2017! = \frac {2017!}{2015!}\frac {2015!}{5^{403}403!}\frac {5^{403}403!}{5^{80}80!}\frac {5^{80}80!}{5^{16}16!}\frac {5^{16}16!}{5^{3}3!} 3!\\$

$\frac {2017!}{10^502} \equiv 12^{502}\frac {2017!}{2015!}\frac {403!}{400!}\frac {16!}{15!}3!\pmod{1000}$

$144\cdot17\cdot16\cdot403\cdot402\cdot401\cdot16\cdot6 = 968\pmod{1000}$

Doug M
  • 57,877