last day (16 days later) » 

16:23
0
Q: Simplify digits population count of n!

user2284570The aim is to sort the least used digits in ascending order beside 0 : for example : 87125897! is 7 then 4 then 6 then 9 then 8 then 3 then 5 then 1 and before last 2 (7 being the first means it is the least appearing digit in the result) 87125891! is 1 then 7 then 2 then 6 then 9 then 4 then 8 t...

"87125897! is 7 ; 4 ; 6 ; 9 ; 8 ; 3 ; 5 ; 1 ; 2" - how did you get this?
It doesn't make sense to me unless they are really close in count. $0 \bmod 3$ have equality among $\{1,4,7\}$ and $\{2,5,8\}$ by sum of digits test in base 10
Or a difference between them a multiple of 3 ...
@JairTaylor The question indicates that they did it by computing the factorial explicitly and then splitting it into digits.
If integer division is the most expensive step, can’t you do the computation with a library that represents large integers in base $10^n$ instead of the typical binary word size?
Also, base conversion can be done much faster than the naive approach of iteratively dividing to extract a constant-size block of digits. See for instance cs.stackexchange.com/questions/21736/…
@ErickWong 87125897! has millions of digits... is that feasible?
Why not choose a smaller example so we can verify it ourselves and check what is meant?
@JairTaylor Yes, it is feasible, but you are right that it is not really obvious. I think it has about 600 million digits and fits into about 30 million 64-bit words. So Schönhage-Strassen multiplication would be warranted, which is $O(n \log n \log \log n)$ in the number of words. It sounds like something you could do within a trillion operations, and it doesn’t take inordinate amounts of memory by modern standards. A feasible but by no means insignificant effort.
16:23
You are very committed to your project...
@ErickWong If integer division is the most expensive step, can’t you do the computation with a library that represents large integers in base 10 n 10n instead of the typical binary word size? what do you suggest for getting it right on such large numbers ?
@RoddyMacPhee : correct, the number of occurrences of each digit on such numbers is very close. Except for 0.
@JairTaylor it has to be done on a large number so the number of occurrences of each digit beside 0 in the number is almost equal. Computing the factorials themselves takes about 30 seconds per factorial on a modern machine.
Once you have one, you can do the equivalent of grade school multiply, and use pigeonhole principle to probably guess it ?
@user2284570 Fair, this is before I realized these factorials are a bit too large for Karatsuba multiplication. I agree it is unlikely you’d find a decimal-based large integer package that implements Strassen
As a small optimization, you can remove all the trailing zeroes in one step by dividing by the appropriate power of 10 (calculated as here).
@Karl but it needs to know how to compute the number of trailing zeros?
@RoddyMacPhee sorry, I don t understand what you mean, is it for counting the digits or computing the result without the factorial?
16:23
@user2284570 see the link in my comment. The number of trailing $0$s in $n!$ is $\sum_{k=1}^{\lfloor\log_5n\rfloor}\left\lfloor\frac n{5^{k}}\right\rfloor$.

last day (16 days later) »