Reputation: 7128
I'm studing computer engineering and we have a hard task.
We have to develop a C# application which can calculate factorial of really big numbers without BIGINT . I mean really big numbers, like 123564891...82598413! . And we don't have to use permission for use custom libraries (like BIGINT) .
Researched it and found a few questions like this, but this question different than others because we have to calculate really big numbers without any custom libraries. I found PoorMans Algorithm . But it's calculating up to 10000 . It's not enough for us.
With my teammates, we found a solution . Let's say we will get factorial of 123 . We will get 123 as String . And then , we will sum 123 , 122 times (it's equal to 123 x 122) . And then sum result 121 times. It will goes like this until reach to 1. So, we will sum two strings.
We create an algorithm for summing strings. We are getting last char of the first number (3 of 123) as an integer (we can use integer, but not bigint) . And get last char of second number as integer (2 of 122). Sum them and found result number's last char (result = x...x5) . We will do it from last char to first char. Finally we will get the result number. But as you know, we should use a while() or for() loop, and for use this loop we need bigint again.
String number = "9878945647978979798798797189"; //we will get factorial of this
for(int i = 0;i < number.Length; i++)
{
// sum all chars one by one
}
we can't use a loop like this, because i
variable will be exceed range of integer and we will get error. So we have to use bigint here. I hope i explained it.
Now here my question, walkthroughs for creating an algorithm which can calculate factorial of really big numbers without using BIGINT .
It's programmer question, not Math.stackexchange.com question, because i need programmatical answers and walkthroughs directly. If i ask this question on Math site, they will give me this list : http://www.luschny.de/math/factorial/FastFactorialFunctions.htm . Probably they won't understand my 'BIGINT problem' .
Upvotes: 1
Views: 1398
Reputation: 17866
You will have to write your own big-integer library. Check Knuth Volume 2 to get started.
Your expectations look a little bit ... over-enthusiastic. You will not be able to calculate the factorial of 9878945647978979798798797189 no matter what you do.
Upvotes: 4