Article View: comp.lang.pascal.misc
Article #61Re: Tough FACTORIAL math problem...
From: Piet van Oostrum
Date: Fri, 16 Feb 1996 11:27
Date: Fri, 16 Feb 1996 11:27
31 lines
1873 bytes
1873 bytes
>>>>> jos@and.nl (Jos A. Horsmeier) (JAH) writes: JAH> In article <wzenrwg142.fsf@stego.cs.ruu.nl>, piet@stego.cs.ruu.nl wrote: JAH> |>>>>> thecrow@iconn.net (The Crow) (TC) writes: JAH> | JAH> |TC> Here is what I am trying to do, I want to find the last NON-ZERO digit JAH> |TC> of a given factorial. For instance, JAH> | JAH> |TC> 5! = 120 JAH> | JAH> |TC> so the last non-zero digit is 2. I want to be able to do this up to JAH> |TC> 1000. Problem is, no matter how huge of a data-type you use, there JAH> |TC> isn't any way for the computer to handle 1000!, it is however possible JAH> |A little thinking before coding solves this problem very easily: JAH> | JAH> |Let N be then number whose factorial you are considering. JAH> | JAH> |What you want is the number of trailing zeroes + 1. JAH> [ clever solution of not-the-posters-problem deleted ... ] JAH> No, that's not what he wanted. A little reading before thinking before JAH> coding may come in handy sometimes ;-) What the original poster wants JAH> is the value of the rightmost non-zero digit of n!. Sorry, I guess that I wrongly interpreted the meaning of the word "find" in the original question. -- Piet van Oostrum <piet@cs.ruu.nl> http://www.cs.ruu.nl/~piet
Technical Details
Message-ID:
<wzvil7wlw1.fsf@stego.cs.ruu.nl>Path:
arc1-ca.pugleaf.net!cs.ruu.nl!usenetReferences:
<4fr8be$ass@news.iconn.net> <wzenrwg142.fsf@stego.cs.ruu.nl> <4fvorm$dfm@beach.and.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cs.ruu.nl!usenet From: piet@stego.cs.ruu.nl (Piet van Oostrum) Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland Subject: Re: Tough FACTORIAL math problem... Date: 16 Feb 1996 12:27:42 +0100 Organization: Universiteit Utrecht, Dept. of Computer Science Sender: piet@stego.cs.ruu.nl Message-ID: <wzvil7wlw1.fsf@stego.cs.ruu.nl> References: <4fr8be$ass@news.iconn.net> <wzenrwg142.fsf@stego.cs.ruu.nl> <4fvorm$dfm@beach.and.nl> NNTP-Posting-Host: stego.cs.ruu.nl In-reply-to: jos@and.nl's message of 15 Feb 1996 17:00:38 GMT X-Newsreader: Gnus v5.0.8