Post Reply 
(49g 50g) Number of Trailing Zeros in N!
06-03-2022, 08:52 PM
Post: #5
RE: (49g 50g) Number of Trailing Zeros in N!
That's pretty neat, especially considering the year that book was published. Very few people at that time had access to computers that could calculate and print such a large number.

Here is an experimental program that hits both points in my previous post. It works with very large numbers, and calculates the number of zeros in almost any base. The "almost" is the issue here- in particular, the base cannot be a prime power or a composite number whose largest prime factor occurs more than once. For example, bases 4, 8, 9, 16, 18 etc. will not return correct answers.

To use the program, first enter the number n. Note: n must be greater than the square of the base or the program will quit with an error. Then for the base, enter the largest prime factor for q. For example, q = 5 will return the correct answer for base 5, 10, 15 and 20 but not 25.

Code:

\<< SWAP OVER I\->BL SWAP \-> q
  \<< SLST\-> 1. - NIP 1 SWAP 2. SWAP
    START q * 1 + ROT OVER * ROT + SWAP
    NEXT DROP
  \>>
\>>

Some notes about the program:

The ListExt command SLST-> is a modified version of OBJ-> for lists which effectively applies NEWOB to every element of the list.

The heart of the program is the phrase q * 1 + which generates successive q-integers (partial sums of the powers of q). This obviates the need to maintain a large list of large integers on the stack.

This program is just as fast as the previous one but still takes over a minute on the physical calculator for 10^1000. EMU48 is your friend here- about 1.5 seconds on my phone.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (49g 50g) Number of Trailing Zeros in N! - John Keith - 06-03-2022 08:52 PM



User(s) browsing this thread: 1 Guest(s)