The last nonzero digits of a very large factorial

How can I calculate the last few digits of a nonzero factorial of a large number?

By and large, I mean that n = 10 ^ 100 or something else ( EDIT : 10 ^ 100 - the value of "n" in n!)
To a few, I mean up to 7-8 ...

I tried to find it and found it -

Last nonzero digit of factorial

I tried to expand this number to two non-zero digits or more, but failed ...

I found other websites on google that showed how to calculate the last number x of digits, but that was unclear, and I couldn't figure it out ...

Can anyone help me with this?

Also, I cannot get this, the last two non-zero digits are 99! 64, so I decided that the last two nonzero digits (199! / 99!) Should also be 64, but they turn out to be 24, I know . I am making an extremely large logical mistake in this, I simply cannot rely on it!

+4
source share
1 answer

The trick for your calculations is that you want to find 3 numbers.

  • The number of factors in the answer is 5.
  • The number of factors in the response.
  • The last few digits of all products of all other primes in the answer.

5 10. 2 5. 2 . , 3, .

5 . n/5 ( ). 5. n/25 ( ). 5. , .

2 2, 4, 8, 16.

.

n, 2 5. f(n). , mod 10 ^ k. , f(i * 10^k + j) = f(j) mod(10^k).

f(n)*f(n/2)*f(n/4)*f(n/5)*f(n/8)*f(n/10)*f(n/16)*.... - . . https://rosettacode.org/wiki/Hamming_numbers , . 10 ^ 100 - ​​ .


. 1 , 2 5 . -, m 10, m * m^(4 * 10^(k-1) - 1) 1 mod 10^k. , "" mod 10 ^ k , 2 5, 0s 2 5, .


. f(n) mod 2 ^ 8 5 ^ 8, mod 10 ^ 8. . n 4 * 390625, 800 . ( , 5 mod 5 ^ 8, 1. .) 4 , MB , .

, , , , , . , , 5 ^ k, . . , , 5 ^ k-1. , , , 1. f , 5, , 5 2 * 5 ^ k, mod 5 ^ k, , 5 5 ^ k. 2 , , 4 * 5 ^ k. , , .


, . 3 15!

15! = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15
    = (1*3*7*9*11*13) * (2*6*14) * (4*12) * (5*15) * (8) * (10)
    = (1*3*7*9*11*13) * 2^3*(1*3*7) * 2^4*(1*3) * 5^2*(1*3) * 2^3*(1) * 10*(1)
    = 2^11 * 5^3 * f(15) * f(15/2) * f(15/4) * f(15/5) * f(15/8) * f(15/10)
    = 2^11 * 5^3 * f(15) * f(15/2) * f(15/4) * f(15/5) * f(15/8) * f(15/10)
    = 10^3 * 2^8 * f(15) * f(7) * f(3) * f(3) * f(1) * f(1)
    Which leads to the calculation...
             256 *   27  *  21  *   3  *   3  *   1  *   1 (mod 1000)
                                                     = 368 (mod 1000)

, 15! = 1307674368000.

+8

Source: https://habr.com/ru/post/1681910/


All Articles