Calculate factorial of any number less than 10000,but I don't know how to start with?
-
Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.
-
Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.
forPower wrote:
Calculate factorial of any number less than 10000
That's a big number to find the factorial of! You won't be able to do it with the existing datatypes, and normal arithmetic techniques. But you could use something like the BigNum[^] library. It is an excellent library and has been around for a while. FYI, I just calculated the factorial of 10000 online (using BigNum) and the answer is: here[^]
forPower wrote:
I just want to get an idea, not the source code.
FYI, BigNum is free of cost and open source (LGPL).
“Follow your bliss.” – Joseph Campbell
-
Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.
Start making space for a lot of digits... :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.
forPower wrote:
Calculate factorial of any number less than 10000,but I don't know how to start with?
Start with 1!. :-D With standard
C
, using an (or two three... :rolleyes: ) array of (circa)40000
unsigned char
s you may roll you own-hand-crafted computation, anyway I doubt the output will be produced in 1 ms... :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]modified on Friday, October 16, 2009 5:16 AM
-
Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.
Can you calculate factorials on paper? Until you get that much squared away, trying to write code is just going to get in your way.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.
0- do you know what a factorial is ? 0.5- did you google/bing about that ? 1- do you know how to calculate factorial on paper ? 2- can you translate that into code ? 2.5- did you even try something ? anyway, don't use recursion.
This signature was proudly tested on animals.
-
0- do you know what a factorial is ? 0.5- did you google/bing about that ? 1- do you know how to calculate factorial on paper ? 2- can you translate that into code ? 2.5- did you even try something ? anyway, don't use recursion.
This signature was proudly tested on animals.
Maximilien wrote:
2- can you translate that into code ? 2.5- did you even try something ?
Unfortunately I think that in this specific case, just translating the factorial logic into code simply won't work. If we use the datatypes that are available to us, and assuming that we use a 64 bit unsigned integer, the largest number that it can hold would be barely sufficient to hold the value of 20 factorial. For holding the resultant value of the computation of 40 factorial, there are no datatypes offered by the tools and languages used usually (it would be larger than what an 128 bit integer can hold!) And the OP wants to find the factorial of not 40, but the factorial of *cough* 10000. The way I know of is to use arbitrary precision arithmetic and the OP didn't know it. He just wanted to know how to get started with it. However, I do agree with you that he could have done a bit of Googling around.
“Follow your bliss.” – Joseph Campbell
-
Maximilien wrote:
2- can you translate that into code ? 2.5- did you even try something ?
Unfortunately I think that in this specific case, just translating the factorial logic into code simply won't work. If we use the datatypes that are available to us, and assuming that we use a 64 bit unsigned integer, the largest number that it can hold would be barely sufficient to hold the value of 20 factorial. For holding the resultant value of the computation of 40 factorial, there are no datatypes offered by the tools and languages used usually (it would be larger than what an 128 bit integer can hold!) And the OP wants to find the factorial of not 40, but the factorial of *cough* 10000. The way I know of is to use arbitrary precision arithmetic and the OP didn't know it. He just wanted to know how to get started with it. However, I do agree with you that he could have done a bit of Googling around.
“Follow your bliss.” – Joseph Campbell
well, if the OP cannot even code a simple factorial for small numbers, then defining it for large numbers is secondary.
This signature was proudly tested on animals.
-
well, if the OP cannot even code a simple factorial for small numbers, then defining it for large numbers is secondary.
This signature was proudly tested on animals.
Maximilien wrote:
well, if the OP cannot even code a simple factorial for small numbers...
That's what I inferred from his post, too.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons