Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I am trying to figure out is a way to compute large factorials, !1000000.

For what it's worth luschny's computer algorithms do a very good job of it.

share|cite|improve this question
You'll have to add more information than that to your question. In my opinion, one shouldn't have to know a programming language to understand a question on this math Q&A site. – Zev Chonoles Apr 26 '12 at 23:01
As Zev is suggesting, this might be appropriate for another SE site. The questions here should be math related. I'm not saying yours isn't, but rather that it is more related to programming than math. – Pedro Tamaroff Apr 26 '12 at 23:23
I included the reference to the code to provide some context for my situation. I made a few edits to hopefully clear things up. – John Apr 26 '12 at 23:31
1,000,000 factorial has about 5,000,000 digits. Do you actually want to calculate that five million digit number exactly? – Gerry Myerson Apr 26 '12 at 23:36
Have you seen Walter Koetke, Computing Factorials -- Accurately, Best of Creative Computing, Volume 1, page 172, available at ? State of the art (for programs written in BASIC in 1976). Perhaps more useful is – Gerry Myerson Apr 27 '12 at 1:17
up vote 3 down vote accepted

Let's take an example which fits on the page, which you can extend if you want. As a product of powers of primorials, you have

$$100!=p_{1}\#^{49}\times p_{2}\#^{24}\times p_{3}\#^{8}\times p_{4}\#^{7}\times p_{5}\#^{2}\times p_{6}\#^{2}\times p_{8}\#\times p_{9}\#\times p_{11}\#\times p_{15}\#\times p_{25}\#$$

where for example $p_{3}\#^{8}$ means the eighth power of the third primorial, i.e. $(2 \times 3 \times 5)^8$.

The reason for an eighth power is that the prime factorisation of $100!$ includes $5^{24}$ and $7^{16}$ with $24-16=8$. One way of calculating this to to take $$\left( \left\lfloor \frac{100}{5^1}\right\rfloor +\left\lfloor \frac{100}{5^2}\right\rfloor +\left\lfloor \frac{100}{5^3}\right\rfloor +\cdots \right) - \left( \left\lfloor \frac{100}{7^1}\right\rfloor +\left\lfloor \frac{100}{7^2}\right\rfloor +\left\lfloor \frac{100}{7^3}\right\rfloor +\cdots \right). $$

share|cite|improve this answer
I understand the notation for primorials, however I am still stuck on how you were able to determine the product of !100 in terms of primorials... – John Apr 27 '12 at 0:39
$100! = 2^{97} 3^{48} 5^{24} 7^{16} 11^{9} 13^{7} 17^{5} 19^{5} 23^{4} 29^{3} 31^{3} 37^{2} 41^{2} 43^{2} 47^{2} 53^{1} 59^{1} 61^{1} 67^{1} 71^{1} 73^{1} 79^{1} 83^{1} 89^{1} 97^{1} $ and then take the first difference of the exponents of the primes to find the exponents of the primorials. I also showed how I found the exponents of the primes, similar to what I did in – Henry Apr 27 '12 at 1:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.