Article View: comp.lang.pascal.misc
Article #64Re: Tough FACTORIAL math problem...
From: Dik T. Winter
Date: Sun, 25 Feb 1996 23:34
Date: Sun, 25 Feb 1996 23:34
15 lines
1420 bytes
1420 bytes
In article <312FFCCF.33209502@armory.com> Tim Martin <tass@armory.com> writes: > 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. The reason you give is not the true reason. Multiplying by 625 introduces 4 new zeros; by pure chance the fifth digit from the rightmost non-zero digit of 624! is even (it is 0). If it had been odd you would have found a wrong result. Compare: if you multiply 10016 by 625 the last non-zero digit of the result is 6, if you had only used 0016 you would have found 1. -- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098 home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Technical Details
Message-ID:
<DnCutM.5ss@cwi.nl>Path:
arc1-ca.pugleaf.net!cwi.nl!dikReferences:
<4gaucn$cdu@beyond.escape.com> <4gh4cq$8eo@agate.berkeley.edu> <312FFCCF.33209502@armory.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland Path: arc1-ca.pugleaf.net!cwi.nl!dik From: dik@cwi.nl (Dik T. Winter) Subject: Re: Tough FACTORIAL math problem... Message-ID: <DnCutM.5ss@cwi.nl> Sender: news@cwi.nl (The Daily Dross) Nntp-Posting-Host: chrysant.cwi.nl Organization: CWI, Amsterdam References: <4gaucn$cdu@beyond.escape.com> <4gh4cq$8eo@agate.berkeley.edu> <312FFCCF.33209502@armory.com> Date: Sun, 25 Feb 1996 23:34:33 GMT