🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.misc
Article #12

Re: Tough FACTORIAL math problem...

#12
From: Tim Martin
Date: Sun, 25 Feb 1996 06:08
30 lines
1820 bytes
Bruce Kaskel wrote:
> 

> So after you have finished the n-th iteration, you have multiplied your
> number by n, removed the trailing zeros, and subtracted 10000 until the
> number is not greater than 10000. Are you claiming that you end up with
> a number with the same last digit as n! ?
> 
> Strictly speaking this is not correct.
> 
> Take the 3125-th iteration. Your algorithm yields 995.
> But the rightmost non-zero digit of 3125! is not 5.
> 
> --Bruce Kaskel

Duh...uh..well, sorry to shoot you down but:

The original USACO problem (where this idea came from...and whoever
posted it to this group needs a serious course in ethics) specified that
you only needed to test up to 1000!....So, his idea works within the
program specs 

BTW-I didn't enter the competition, but I also solved it that particular
way...with a little more clumsy approach using strings instead of
longints, but the basic concept is the same - you only need to save the
last 4 non-zero digits, because you are only ever multiplying the result
by something less than 1000.

Tim 
tass@armory.com
Technical Details
Message-ID: <312FFCCF.33209502@armory.com>
Path: arc1-ca.pugleaf.net!usenet.cis.ufl.edu!caen!usenet
References: <4fr8be$ass@news.iconn.net> <4g2n5u$kqj@sun001.spd.dsccc.com> <danpop.824595562@rscernix> <4gaucn$cdu@beyond.escape.com> <4gh4cq$8eo@agate.berkeley.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!usenet.cis.ufl.edu!caen!usenet
From: Tim Martin <tass@armory.com>
Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
Subject: Re: Tough FACTORIAL math problem...
Date: Sun, 25 Feb 1996 01:08:15 -0500
Organization: University of Michigan Engineering, Ann Arbor
Message-ID: <312FFCCF.33209502@armory.com>
References: <4fr8be$ass@news.iconn.net> <4g2n5u$kqj@sun001.spd.dsccc.com> <danpop.824595562@rscernix> <4gaucn$cdu@beyond.escape.com> <4gh4cq$8eo@agate.berkeley.edu>
NNTP-Posting-Host: tass@pm085-07.dialip.mich.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.3 i486)