http://www.codechef.com/wiki/tutorial-small-factorials
On Fri, Feb 4, 2011 at 11:52 PM, Dave <dave_and_da...@juno.com> wrote: > Oh. That is supposed to be t. So the line actually could read > t /= 10000; > Sorry for the typo. > > Dave > > On Feb 4, 11:58 am, Rahul Verma <rahulverma....@gmail.com> wrote: > > @Dave > > In the line t=p/1000000; > > what is the value of p here or what it means? > > > > On Feb 4, 9:57 pm, Dave <dave_and_da...@juno.com> wrote: > > > > > > > > > @Rahul: Given that 100! < 100^100 = 10^200, we know that 100! has less > > > than 200 digits. Assuming 32-bit integers, we might choose to store > > > anywhere from 1 to 7 digits in an integer, realizing that we have to > > > multiply the integer by a number up to 100 and still want the result > > > to be less than 2^31. I'll use 5 digits in an integer. Then the > > > computation can look something like this, assuming that you have > > > already read n, the number whose factorial you want: > > > > > int a[40], i, j, l, t; > > > a[0] = 1; // rightmost "digit" of number = 0! > > > l = 1; // the active number of elements of a[] used. > > > for( i = 2 ; i < n ; ++i ) > > > { > > > t = 0; // the carry into the next product > > > for( j = 0 ; j < l ; ++j ) > > > { > > > t += i * a[j]; // multiply digit by i and add carry > > > a[j] = t % 10000; // extract 5 digits > > > t = p / 100000; // calculate next carry > > > } > > > if( t > 0 ) // does the number need to add a digit? > > > a[l++] = t; > > > } > > > printf("%i",a[l-1]); > > > for( i = l-2 ; i >= 0 ; --i ) > > > printf("%.5i",a[i]); > > > printf("\n"); > > > > > Dave > > > > > On Feb 4, 10:19 am, Rahul Verma <rahulverma....@gmail.com> wrote: > > > > > > Hi Group, > > > > > > Let me help to solve this problem of SPOJhttps:// > www.spoj.pl/problems/FCTRL2/ > > > > > > The approach to solve the problem is very easy and I'm confused that > > > > how to store such a large no. like 100! in a variable using C++ > > > > Language. > > > > > > Thanx & Regards, > > > > Rahul Verma- Hide quoted text - > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.