Article View: comp.lang.pascal.misc
Article #43Re: Tough FACTORIAL math problem...
From: h.huisman Henk Huisman
Date: Fri, 16 Feb 1996 13:16
Date: Fri, 16 Feb 1996 13:16
37 lines
1930 bytes
1930 bytes
In <4fr8be$ass@news.iconn.net>, thecrow@iconn.net (The Crow) writes:
>Here is what I am trying to do, I want to find the last NON-ZERO digit of a
>given factorial. For instance,
>
>5! = 120
>
>so the last non-zero digit is 2. I want to be able to do this up to 1000.
>Problem is, no matter how huge of a data-type you use, there isn't any way for
>the computer to handle 1000!, it is however possible to find the last non-zero
>digit somehow. One thing I have tried is as I went through mulitplying the
>series of numbers in the factorial (5 * 4 * 3 * 2) I would remove all the
>trailing ZEROS, I got this to work up to 789, but it wont work with 1000 and i
>am not really sure why. If anyone has a clue how I can do this let me know.
>
>--
>The Crow - thecrow@iconn.net
>"It can't rain all the time"
>-Kryptology
>
You will get a zero at the end for every factor of 5 in the number:
2's are available in abundance.
So: nzeroes:=0;
for i:=1 to n
do begin
nfives:={factor i, not too hard, and get the exponent of 5.}
nzeroes:=nzeroes+nfives;
end;
Henk.
-----This is an airconditioned room, do not open Windows.-----
Henk Huisman h.huisman@wbmt.tudelft.nl
Systems and Control Group Mekelweg 2
Delft University of Technology NL-2628 CD Delft
--------------------------------------------------------------
Technical Details
Message-ID:
<4g2033$cvr@mo6.rc.tudelft.nl>Path:
arc1-ca.pugleaf.net!tudelft.nl!newsReferences:
<4fr8be$ass@news.iconn.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!tudelft.nl!news From: h.huisman@wbmt.tudelft.nl [Henk Huisman] 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 13:16:19 GMT Organization: Delft University of Technology, The Netherlands Message-ID: <4g2033$cvr@mo6.rc.tudelft.nl> References: <4fr8be$ass@news.iconn.net> Reply-To: h.huisman@wbmt.tudelft.nl NNTP-Posting-Host: dutw195.tudelft.nl X-Newsreader: IBM NewsReader/2 v1.02