Is there some kind of mathematical "optimal" base that will accelerate factorial calculation?
Background: Just for fun, I am implementing my own bigum library. (-: Is this my first mistake? :-). I experiment with various bases used in internal representation and regression testing, writing out the exact values (in decimal form) for n factorial (n!).
The way my bignum library represents integers and does multiplication, time is proportional to the total number of "1" bits in the internal representation of n !. Using base 2, 4, 8, 16, 2 ^ 8, 2 ^ 30, etc. In my internal view, everyone gives me exactly the same total number of bits "1" for any particular number.
If I made a mistake, any factorial (n!) Represented in base 18 has less than “1” bit than the same value presented in base 10 or either base 16 or base 19. And so (in principle), using base 18, my bigum library will work faster than using base 10 or some binary base 2 ^ w or base 19. I think this is due to the fact that n! either shorter or has more “trailing zeros” or both when printing on base 18 than in base 10 or either in base 16 or base 19. Is there any other base that will work even better than base 18? In other words, is there a base that represents n! with even fewer bits "1" than the base 18?
This is not a duplicate of "What is a convenient base for a signal library and primitive testing algorithm?" because I suspect that the "optimal base for working with integers, which are known to be large factorials, with many factors 2 and 3," differs from the "optimal base for working with integers that do not have any small factors and possibly prime. " (-: speeds up factorial calculations - perhaps due to other types of calculations - is my second mistake ?: -)
edit: For example:
(decimal) 16! == (decimal ) == 20,922,789,888,000 // uses decimal 14 "1" bits (dozenal ) == 2,41A,B88,000,000 // uses decimal 10 "1" bits (hexadecimal) == 130,777,758,000 // uses decimal 18 "1" bits (octadecimal) == 5F,8B5,024,000 // uses decimal 14 "1" bits
(I store more or less digits on the right, without commas, as well as some metadata overhead). (Although you might think that "as the base grows, you will use less than" 1 "bit to represent the given number" or "As the base grows, you will use fewer non-zero digits to represent the given number," the above example shows that this is not always So.)
I save each digit as a small integer ("int" or "long int" or "byte"). Is there any other smart way to store numbers? I am sure my computer stores these integers in binary format - each digit "1", "2", "4", "8" and "G" uses one bit of "1"; each digit "3", "5", "6", "9" and "A" uses two "1" bits; each digit "7" and "B" uses three "1" bits; each “F” digit uses four “1” bits, etc.
Both decimal and octal representations of this value (16!) Require 14 "1" bits. Therefore, I made a mistake in my previous calculations: for every n representing n! in the octadecimal, the bits "1" are not always less than the value equal to the decimal value. But the question still remains: is there any other “optimal” base that requires the least amount of 1 bit to store large factorials?
Someone asks: "How do you store these numbers?" Well, that’s exactly my question - what is the best way to store numbers of form n !? I could internally use the numbers in base 10 or some kind of base of two bases, or base 18, or some other base. Which one is better? I could store these integers internally as a 1D array of digits, the length of which is required to store all the digits. Is there a reasonable way to print 100! in decimal without such an array?