@jitendra: your python code is awesome and it works.:)

On Wed, May 12, 2010 at 6:37 PM, divya jain <sweetdivya....@gmail.com>wrote:

> thanx to all 4 the solutions..
>
>
> On 3 May 2010 18:39, Varun Nagpal <varun.nagp...@gmail.com> wrote:
>
>> @Rajesh gave a simple elegant solution.
>>
>> A look at a Linux calculator : you can even calculate 999999! =
>> 8.854887824e+5584950 ....in few seconds. I just looked at the code(its open
>> source right!), which is not so easy to understand in few minutes.
>>
>> Here is the some part of code I extracted from source files:
>>
>> /* Size of the multiple precision values */
>> #define MP_SIZE 1000
>>
>> /* Base for numbers */
>> #define MP_BASE 10000
>>
>> /* Object for a high precision floating point number representation
>>  *
>>  * x = sign * (MP_BASE^(exponent-1) + MP_BASE^(exponent-2) + ...)
>>  */
>> typedef struct
>> {
>>    /* Sign (+1, -1) or 0 for the value zero */
>>    int sign; //, im_sign;
>>
>>    /* Exponent (to base MP_BASE) */
>>    int exponent; //, im_exponent;
>>
>>    /* Normalized fraction */
>>    int fraction[MP_SIZE]; //, im_fraction[MP_SIZE];
>> } MPNumber;
>>
>>
>> void mp_factorial(const MPNumber *x, MPNumber *z)
>> {
>>     int i, value;
>>
>>     /* 0! == 1 */
>>     if (mp_is_zero(x)) {
>>         mp_set_from_integer(1, z);
>>         return;
>>     }
>>     if (!mp_is_natural(x)) {
>>         /* Translators: Error displayed when attempted take the factorial
>> of a fractional number */
>>         mperr(_("Factorial is only defined for natural numbers"));
>>         mp_set_from_integer(0, z);
>>         return;
>>     }
>>
>>     /* Convert to integer - if couldn't be converted then the factorial
>> would be too big anyway */
>>     value = mp_cast_to_int(x);
>>     mp_set_from_mp(x, z);
>>     for (i = 2; i < value; i++)
>>         mp_multiply_integer(z, i, z);
>> }
>>
>> mp_multiply_integer(z, i, z) subroutine is too big too put in here, too
>> see its code visit:  http://live.gnome.org/Gcalctool
>>  <http://live.gnome.org/Gcalctool>
>> On Mon, May 3, 2010 at 2:34 PM, Anil C R <cr.a...@gmail.com> wrote:
>>
>>> @Jitendra
>>> but that's no fun [?]
>>>
>>> -----
>>> Anil
>>>
>>>
>>>
>>> On Mon, May 3, 2010 at 5:12 PM, vignesh radhakrishnan <
>>> rvignesh1...@gmail.com> wrote:
>>>
>>>> @siddharth and prasoon either design a very long integer library
>>>> yourself, or use gmp library in cpp or BigInteger Class in java.
>>>>
>>>> Regards,
>>>> vignesh
>>>>
>>>> On 3 May 2010 09:46, siddharth srivastava <akssps...@gmail.com> wrote:
>>>>
>>>>> But is there any way to accomplish this without an array ? Even for
>>>>> 100!.
>>>>>
>>>>>
>>>>> On 2 May 2010 06:15, Prasoon Mishra <prasoonbluel...@gmail.com> wrote:
>>>>>
>>>>>> I think challenge here is not the Execution time, but the storage. 300
>>>>>> ! or 400! should generally go beyond the storage capabilities of long 
>>>>>> long
>>>>>> ints in cpp.
>>>>>> @ Rohit Saraf: Hence, I don't know if even tail recursion will
>>>>>> ultimately be able to store the output.
>>>>>> I think Rajesh Patidar's answer fits the bill well, in terms of
>>>>>> storage.
>>>>>>
>>>>>>
>>>>>> On Sun, May 2, 2010 at 2:23 PM, vignesh radhakrishnan <
>>>>>> rvignesh1...@gmail.com> wrote:
>>>>>>
>>>>>>> I agree with abhijith. But given some very large x for which i would
>>>>>>> have to find factorial.
>>>>>>> I would either
>>>>>>> (i) use gmp in cpp or BigInteger or java if its not a lab exercise or
>>>>>>> an interview
>>>>>>> (ii) use simple brute multiplication algorithm.
>>>>>>> The second approach requires
>>>>>>>          (a) The no. of digits in n! for making storage available
>>>>>>>          (b) The calculation itself which I would brute force
>>>>>>>
>>>>>>> References:
>>>>>>>
>>>>>>> http://inder-gnu.blogspot.com/2009/08/find-number-of-digits-in-factorial-of.html
>>>>>>>
>>>>>>> http://stackoverflow.com/questions/1113167/can-one-know-how-large-a-factorial-would-be-before-calculating-it
>>>>>>> http://delphiforfun.org/programs/big_factorials.htm
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 2 May 2010 13:59, Rohit Saraf <rohit.kumar.sa...@gmail.com>wrote:
>>>>>>>
>>>>>>>> google it... u will gt it
>>>>>>>>
>>>>>>>> i am on mobile... cannot explain now..
>>>>>>>>
>>>>>>>> On 5/2/10, divya jain <sweetdivya....@gmail.com> wrote:
>>>>>>>> > wat is tail recursion plz explan in detail
>>>>>>>> >
>>>>>>>> > On 2 May 2010 08:15, Rohit Saraf <rohit.kumar.sa...@gmail.com>
>>>>>>>> wrote:
>>>>>>>> >
>>>>>>>> >> @divya use tail recursion and rest should be fine..
>>>>>>>> >>
>>>>>>>> >> --
>>>>>>>> >> --------------------------------------------------
>>>>>>>> >> Rohit Saraf
>>>>>>>> >> Second Year Undergraduate,
>>>>>>>> >> Dept. of Computer Science and Engineering
>>>>>>>> >> IIT Bombay
>>>>>>>> >> http://www.cse.iitb.ac.in/~rohitfeb14<http://www.cse.iitb.ac.in/%7Erohitfeb14>
>>>>>>>> <http://www.cse.iitb.ac.in/%7Erohitfeb14>
>>>>>>>> >>
>>>>>>>> >> --
>>>>>>>> >> You received this message because you are subscribed to the
>>>>>>>> Google Groups
>>>>>>>> >> "Algorithm Geeks" group.
>>>>>>>> >> To post to this group, send email to algoge...@googlegroups.com.
>>>>>>>> >> To unsubscribe from this group, send email to
>>>>>>>> >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>>>>>>> <algogeeks%2bunsubscr...@googlegroups.com<algogeeks%252bunsubscr...@googlegroups.com>
>>>>>>>> >
>>>>>>>> >> .
>>>>>>>> >> For more options, visit this group at
>>>>>>>> >> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>>> >>
>>>>>>>> >>
>>>>>>>> >
>>>>>>>> > --
>>>>>>>> > You received this message because you are subscribed to the Google
>>>>>>>> Groups
>>>>>>>> > "Algorithm Geeks" group.
>>>>>>>> > To post to this group, send email to algoge...@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.
>>>>>>>> >
>>>>>>>> >
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> --------------------------------------------------
>>>>>>>> Rohit Saraf
>>>>>>>> Second Year Undergraduate,
>>>>>>>> Dept. of Computer Science and Engineering
>>>>>>>> IIT Bombay
>>>>>>>> http://www.cse.iitb.ac.in/~rohitfeb14<http://www.cse.iitb.ac.in/%7Erohitfeb14>
>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>>> To post to this group, send email to algoge...@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.
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> There are two kinds of people. Those who care for others and The
>>>>>>> others
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>> To post to this group, send email to algoge...@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.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algoge...@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.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Siddharth Srivastava
>>>>>
>>>>> Human Knowledge is for all
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algoge...@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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> There are two kinds of people. Those who care for others and The others
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algoge...@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.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@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.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@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.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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.
>



-- 
Thanks & Regards
Nikhil Agarwal
Senior Undergraduate
Computer Science & Engineering,
National Institute Of Technology, Durgapur,India
http://tech-nikk.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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.

<<329.png>>

Reply via email to