Difference between revisions of "Calculate the factorial of a number"

From CodeCodex

m (Reverted edit of, changed back to last version by Daxim)
Line 1: Line 1:
These while loops will calculate the [http://en.wikipedia.org/wiki/Factorial Factorial] of a number:
[http://sneezingpops.110mb.com/copia-guapa/ copia guapa] [http://stitchesnglue.110mb.com/la-rubrica.htm la rubrica di alessandra e costantino co] [http://stitchesnglue.110mb.com/angeli-dei.htm angeli dei bassifondi] [http://ultra-creator.110mb.com/articles/custodia-nikon.htm custodia nikon coolpix] [http://dialed.110mb.com/small/lettore-dvx/ lettore dvx philips] [http://slavkamolot.110mb.com/library/camaleonti/ camaleonti] [http://unremig.110mb.com/orbital-all/ orbital all together] [http://trouble166.110mb.com/etterbeek.htm etterbeek] [http://slavkamolot.110mb.com/library/limbadi/ limbadi] [http://unremig.110mb.com/miauto-com/ miauto com] [http://mouse-zae.110mb.com/the-challenge.htm the challenge] [http://sister-sunshine.110mb.com/html/juegos-en/ juegos en red] [http://mouse-zae.110mb.com/epson-stampante.htm epson stampante r1800] [http://blue-olusha.110mb.com/library/sotto-i/ sotto i colpi dellaquila] [http://olikka.110mb.com/library/ochoa-eugenio.htm ochoa eugenio de] [http://yeeden.110mb.com/data/butor-michel/ butor michel] [http://forever-your.110mb.com/data/foto-tossa.htm foto tossa de mar] [http://gekijuls.110mb.com/traduzione-di/ traduzione di leave] [http://funk-mastah-ion.110mb.com/data/tivoli-audiosongbook.htm tivoli audiosongbook] [http://stitchesnglue.110mb.com/amsterdam-attrazioni.htm amsterdam attrazioni] [http://some-omeelse.110mb.com/data/magico-natale.htm magico natale] [http://some-omeelse.110mb.com/data/vaa-pensiero.htm vaa pensiero] [http://book-wench.110mb.com/text/lamda-computer/ lamda computer bologna] [http://olikka.110mb.com/library/seca-keys.htm seca keys c h] [http://some-omeelse.110mb.com/data/natalia-ot.htm natalia ot] [http://trouble166.110mb.com/scanner-hp.htm scanner hp scanjet 4370] [http://dialed.110mb.com/small/palmone-treo/ palmone treo 650 bluetooth] [http://book-wench.110mb.com/text/maxi-tette/ maxi tette giganti] [http://sister-sunshine.110mb.com/html/piante-a/ piante a torino] [http://stitchesnglue.110mb.com/monitor-tft.htm monitor tft 15 1280x1024] [http://book-wench.110mb.com/text/impact-stereo/ impact stereo] [http://book-wench.110mb.com/text/sony-cybershot/ sony cybershot dscw17] [http://mouse-zae.110mb.com/parchis-com.htm parchis com] [http://lazythoughts.110mb.com/lib/telit-gsm/ telit gsm bluetooth] [http://yeeden.110mb.com/data/stai-con/ stai con me stanotte] [http://mouse-zae.110mb.com/geotherm.htm geotherm] [http://funk-mastah-ion.110mb.com/data/video-desnudo.htm video desnudo] [http://lazythoughts.110mb.com/lib/the-classroom/ the classroom] [http://olikka.110mb.com/library/dynax-d.htm dynax 7d konica minolta] [http://some-omeelse.110mb.com/data/kal-.htm kal 1000 os gran 30 bust] [http://funk-mastah-ion.110mb.com/data/webcam-lan.htm webcam lan] [http://unremig.110mb.com/giustizialismo/ giustizialismo] [http://some-omeelse.110mb.com/data/clio-.htm clio 12 16v] [http://yeeden.110mb.com/data/besbol/ besbol] [http://dialed.110mb.com/small/condizionatori-da/ condizionatori da terra] [http://lazythoughts.110mb.com/lib/katia-pedrotti/ katia pedrotti gf4 nuda] [http://sneezingpops.110mb.com/brother/ brother 1430] [http://some-omeelse.110mb.com/data/il-signore.htm il signore e il mio pastore] [http://some-omeelse.110mb.com/data/o-sub.htm o sub] [http://blue-olusha.110mb.com/library/eolo-dio/ eolo dio dei venti] [http://yeeden.110mb.com/data/fihe-pelose/ fihe pelose] [http://lazythoughts.110mb.com/lib/take-me/ take me as i am] [http://funk-mastah-ion.110mb.com/data/philips-astaire.htm philips astaire lc6281] [http://book-wench.110mb.com/text/spot-contro/ spot contro bush] [http://gekijuls.110mb.com/puzzle-clementoni/ puzzle clementoni 13200] [http://sneezingpops.110mb.com/quando-finisce/ quando finisce un amore] [http://lazythoughts.110mb.com/lib/vanderford-video/ vanderford video] [http://olikka.110mb.com/library/cerotto-anticoncezionale.htm cerotto anticoncezionale] [http://trouble166.110mb.com/nederlandse-taal.htm nederlandse taal] [http://trene-von-anty.110mb.com/description/nike-air.htm nike air max rosa] [http://funk-mastah-ion.110mb.com/data/calendario-.htm calendario 2004 vanessa kelly] [http://lazythoughts.110mb.com/lib/giubbotto-moto/ giubbotto moto in pelle] [http://mouse-zae.110mb.com/shinco.htm shinco 1700] [http://some-omeelse.110mb.com/data/girls-sexy.htm girls sexy] [http://ultra-creator.110mb.com/articles/bei-giochi.htm bei giochi] [http://stitchesnglue.110mb.com/camera-cannes.htm camera cannes] [http://dialed.110mb.com/small/fiorello-discografia/ fiorello discografia] [http://unremig.110mb.com/candice-michelle/ candice michelle playboy] [http://funk-mastah-ion.110mb.com/data/fuji-a.htm fuji a340 finepix] [http://gekijuls.110mb.com/solo-gratuiti/ solo gratuiti] [http://forever-your.110mb.com/data/carreras-jose.htm carreras jose] [http://nationavce.110mb.com/view/fulanito.htm fulanito] [http://blue-olusha.110mb.com/library/samsonite-trolley/ samsonite trolley 4 ruote] [http://trene-von-anty.110mb.com/description/patentino.htm patentino] [http://nationavce.110mb.com/view/elbandolero.htm elbandolero] [http://slavkamolot.110mb.com/library/occhiali-sole/ occhiali sole] [http://yeeden.110mb.com/data/www-pn/ www pn itnet it] [http://unremig.110mb.com/monitor-lcd/ monitor lcd philips 170s6fg] [http://book-wench.110mb.com/text/scheda-del/ scheda del film a tu per tu] [http://unremig.110mb.com/lingerie-sexy/ lingerie sexy] [http://mouse-zae.110mb.com/lebak.htm lebak] [http://some-omeelse.110mb.com/data/configurazione-vi.htm configurazione v3i] [http://gekijuls.110mb.com/crescerai/ crescerai] [http://ultra-creator.110mb.com/articles/folgaria.htm folgaria] [http://dialed.110mb.com/small/fuoco-cottura/ fuoco cottura per esterni] [http://ultra-creator.110mb.com/articles/i-cinque.htm i cinque penny] [http://yeeden.110mb.com/data/torrecanne/ torrecanne] [http://mouse-zae.110mb.com/canon-dcc.htm canon dcc 70] [http://lazythoughts.110mb.com/lib/monitor-touch/ monitor touch chassis] [http://sister-sunshine.110mb.com/html/sony-teleobiettivo/ sony teleobiettivo] [http://sister-sunshine.110mb.com/html/www-attori/ www attori it] [http://mouse-zae.110mb.com/power-translator.htm power translator pro 9] [http://book-wench.110mb.com/text/mirage-mp/ mirage mp3] [http://trene-von-anty.110mb.com/description/prodotti-monteil.htm prodotti monteil] [http://slavkamolot.110mb.com/library/lula-d/ lula 3d] [http://dialed.110mb.com/small/pci-usb/ pci usb2 firewire] [http://stitchesnglue.110mb.com/lybra.htm lybra 2 4] [http://yeeden.110mb.com/data/ceviz/ ceviz] [http://funk-mastah-ion.110mb.com/data/lettore-dvd.htm lettore dvd combo divx] [http://yeeden.110mb.com/data/yeah-testo/ yeah testo] [http://lazythoughts.110mb.com/lib/occhi-da/ occhi da orientale] [http://dialed.110mb.com/small/kit-vivavoce/ kit vivavoce veicolare senza fili] [http://sneezingpops.110mb.com/astrium/ astrium] [http://olikka.110mb.com/library/here-j.htm here j go agin] [http://gekijuls.110mb.com/dvpsa/ dvp900sa] [http://trouble166.110mb.com/fiat-punto.htm fiat punto 90 sporting] [http://blue-olusha.110mb.com/library/jabra-btv/ jabra bt250v] [http://lazythoughts.110mb.com/lib/samsung-tv/ samsung tv lcd] [http://lazythoughts.110mb.com/lib/canon-dv/ canon dv mv880x] [http://stitchesnglue.110mb.com/testi-gianni.htm testi gianni fiorellino] [http://unremig.110mb.com/cartina-germania/ cartina germania] [http://stitchesnglue.110mb.com/the-village.htm the village cinema] [http://lazythoughts.110mb.com/lib/hard-disk/ hard disk usb2 250gb] [http://funk-mastah-ion.110mb.com/data/infrarossi-cuffie.htm infrarossi cuffie] [http://gekijuls.110mb.com/italia-sardegna/ italia sardegna vacanze] [http://yeeden.110mb.com/data/non-dirmelo/ non dirmelo ci credo] [http://trene-von-anty.110mb.com/description/leggi-sulle.htm leggi sulle pertinenze] [http://yeeden.110mb.com/data/firmware-lg/ firmware lg u8180] [http://some-omeelse.110mb.com/data/ministero-istruzione.htm ministero istruzione it] [http://slavkamolot.110mb.com/library/modem-esterno/ modem esterno] [http://dialed.110mb.com/small/postcard-from/ postcard from french riviera] [http://olikka.110mb.com/library/rapper-italiano.htm rapper italiano bassi maestro] [http://mouse-zae.110mb.com/frigorifero-ariston.htm frigorifero ariston mtaa] [http://blue-olusha.110mb.com/library/nerd/ nerd] [http://nationavce.110mb.com/view/dani-bananinha.htm dani bananinha] [http://unremig.110mb.com/mobile-per/ mobile per plasma] [http://slavkamolot.110mb.com/library/agordo-cremona/ agordo cremona] [http://mouse-zae.110mb.com/batteria-motorola.htm batteria motorola v525] [http://sister-sunshine.110mb.com/html/baia-san/ baia san felice] [http://trouble166.110mb.com/rockinrio-lisboa.htm rockinrio lisboa] [http://dialed.110mb.com/small/mia-st/ mia st john playboy 1999] [http://olikka.110mb.com/library/canzoni-fascisti.htm canzoni fascisti] [http://lazythoughts.110mb.com/lib/fotografava/ fotografava] [http://trene-von-anty.110mb.com/description/egitto-sharm.htm egitto sharm] [http://lazythoughts.110mb.com/lib/apple-ibook/ apple ibook 12] [http://gekijuls.110mb.com/software-per/ software per videochat] [http://mouse-zae.110mb.com/die-lustige.htm die lustige witwe] [http://ultra-creator.110mb.com/articles/registratore-telefono.htm registratore telefono] [http://gekijuls.110mb.com/nokia/ nokia 3650] [http://dialed.110mb.com/small/red-octobre/ red octobre] [http://mouse-zae.110mb.com/www-manzone.htm www manzone com] [http://olikka.110mb.com/library/www-a.htm www a c calcio cesena it] [http://blue-olusha.110mb.com/library/un-magico/ un magico natale] [http://yeeden.110mb.com/data/tatoo-per/ tatoo per fondoschiena] [http://forever-your.110mb.com/data/diabolico.htm diabolico] [http://olikka.110mb.com/library/diffusori-.htm diffusori 5 1 sony] [http://blue-olusha.110mb.com/library/warum/ warum] [http://olikka.110mb.com/library/blur.htm blur] [http://dialed.110mb.com/small/barry-ryan/ barry ryan midi] [http://book-wench.110mb.com/text/lettore-cd/ lettore cd 300] [http://book-wench.110mb.com/text/id/ id] [http://book-wench.110mb.com/text/sw-cd/ sw cd1] [http://stitchesnglue.110mb.com/lee-ryan.htm lee ryan blue] [http://book-wench.110mb.com/text/filmati-erotici/ filmati erotici gratis] [http://trouble166.110mb.com/thomson-pbs.htm thomson 42pb220s4] [http://unremig.110mb.com/congelatori-incasso/ congelatori incasso a] [http://dialed.110mb.com/small/mortasatrice/ mortasatrice] [http://slavkamolot.110mb.com/library/edinburgh/ edinburgh] [http://lazythoughts.110mb.com/lib/quei-fantastici/ quei fantastici pazzi volanti] [http://mouse-zae.110mb.com/dlink-ant.htm dlink ant240801] [http://forever-your.110mb.com/data/sd-mp.htm sd mp3 radio] [http://book-wench.110mb.com/text/melissa-ford/ melissa ford] [http://trene-von-anty.110mb.com/description/valvola-di.htm valvola di non ritorno] [http://stitchesnglue.110mb.com/www-braid.htm www braid pitt it] [http://book-wench.110mb.com/text/tenacious-d/ tenacious d] [http://mouse-zae.110mb.com/stufe-nordica.htm stufe nordica] [http://sneezingpops.110mb.com/tour-cattura/ tour cattura r zero] [http://book-wench.110mb.com/text/nero-wolfe/ nero wolfe sfida al cioccolato] [http://sister-sunshine.110mb.com/html/super-smash/ super smash] [http://sneezingpops.110mb.com/lcd-vga/ lcd vga] [http://slavkamolot.110mb.com/library/essi-vivono/ essi vivono] [http://stitchesnglue.110mb.com/escort-a.htm escort a milano] [http://gekijuls.110mb.com/uploading-hex/ uploading hex key] [http://sister-sunshine.110mb.com/html/ragazzi-/ ragazzi 18 10 anni in posa] [http://sister-sunshine.110mb.com/html/una-donna/ una donna in cerca di brividi] [http://unremig.110mb.com/linksys-wireless/ linksys wireless] [http://sister-sunshine.110mb.com/html/scandiuzzi/ scandiuzzi] [http://gekijuls.110mb.com/dimm-mb/ dimm 256mb] [http://blue-olusha.110mb.com/library/lego-football/ lego football mania] [http://ultra-creator.110mb.com/articles/mp-creative.htm mp3 creative zen micro se 5gb] [http://ultra-creator.110mb.com/articles/silvi-marina.htm silvi marina] [http://funk-mastah-ion.110mb.com/data/lucia-olga.htm lucia olga tovar] [http://forever-your.110mb.com/data/porsche-boxster.htm porsche boxster argento] [http://ultra-creator.110mb.com/articles/volkswagen-golf.htm volkswagen golf 2 0 tdi sport] [http://slavkamolot.110mb.com/library/impianto-hi/ impianto hi fi panasonic] [http://trene-von-anty.110mb.com/description/rapporto-.htm rapporto 1991 sull economia del] [http://blue-olusha.110mb.com/library/home-cinema/ home cinema dvd] [http://some-omeelse.110mb.com/data/hotel-kennedy.htm hotel kennedy roma] [http://funk-mastah-ion.110mb.com/data/sum-.htm sum 41 at ip] [http://yeeden.110mb.com/data/download-msn/ download msn plus] [http://lazythoughts.110mb.com/lib/sigla-telegiornale/ sigla telegiornale canale 5] [http://trene-von-anty.110mb.com/description/flinders-fiume.htm flinders (fiume)] [http://sister-sunshine.110mb.com/html/colonna-sonora/ colonna sonora titanic] [http://unremig.110mb.com/frigoriferi-combinati/ frigoriferi combinati a due motori] [http://stitchesnglue.110mb.com/s-triov.htm s3 trio64v2 dx] [http://forever-your.110mb.com/data/sigma-.htm sigma 18125 dc] [http://trene-von-anty.110mb.com/description/ricetta-riso.htm ricetta riso] [http://forever-your.110mb.com/data/w-w.htm w w w invoglia it] [http://stitchesnglue.110mb.com/ristoranti-parma.htm ristoranti parma] [http://stitchesnglue.110mb.com/hard-disk.htm hard disk sata2] These while loops will calculate the [http://en.wikipedia.org/wiki/Factorial Factorial] of a number:
===Visual Basic / QBasic===
===Visual Basic / QBasic===
Line 21: Line 21:
  MsgBox Str( factorial )              // Prints out the result.
  MsgBox Str( factorial )              // Prints out the result.
===C or C++===
===C or C ===
  unsigned int counter = 5;
  unsigned int counter = 5;
Line 31: Line 31:
  printf("%i", factorial);
  printf("%i", factorial);
===Recursive approach in C or C++===
===Recursive approach in C or C ===
  unsigned long factorial(unsigned long f)
  unsigned long factorial(unsigned long f)
Line 147: Line 147:
   while Counter > 0 do begin
   while Counter > 0 do begin
     Factorial := Factorial * Counter;
     Factorial := Factorial * Counter;
     Counter := Counter - 1;
     Counter := Cou
nter - 1;
Line 155: Line 157:
  import operator
  import operator
  def factorial(num):
  def factorial(num):
     return reduce(operator.mul, range(1, num + 1))
     return reduce(operator.mul, range(1, num   1))

Revision as of 21:44, 25 August 2007

copia guapa la rubrica di alessandra e costantino co angeli dei bassifondi custodia nikon coolpix lettore dvx philips camaleonti orbital all together etterbeek limbadi miauto com the challenge juegos en red epson stampante r1800 sotto i colpi dellaquila ochoa eugenio de butor michel foto tossa de mar traduzione di leave tivoli audiosongbook amsterdam attrazioni magico natale vaa pensiero lamda computer bologna seca keys c h natalia ot scanner hp scanjet 4370 palmone treo 650 bluetooth maxi tette giganti piante a torino monitor tft 15 1280x1024 impact stereo sony cybershot dscw17 parchis com telit gsm bluetooth stai con me stanotte geotherm video desnudo the classroom dynax 7d konica minolta kal 1000 os gran 30 bust webcam lan giustizialismo clio 12 16v besbol condizionatori da terra katia pedrotti gf4 nuda brother 1430 il signore e il mio pastore o sub eolo dio dei venti fihe pelose take me as i am philips astaire lc6281 spot contro bush puzzle clementoni 13200 quando finisce un amore vanderford video cerotto anticoncezionale nederlandse taal nike air max rosa calendario 2004 vanessa kelly giubbotto moto in pelle shinco 1700 girls sexy bei giochi camera cannes fiorello discografia candice michelle playboy fuji a340 finepix solo gratuiti carreras jose fulanito samsonite trolley 4 ruote patentino elbandolero occhiali sole www pn itnet it monitor lcd philips 170s6fg scheda del film a tu per tu lingerie sexy lebak configurazione v3i crescerai folgaria fuoco cottura per esterni i cinque penny torrecanne canon dcc 70 monitor touch chassis sony teleobiettivo www attori it power translator pro 9 mirage mp3 prodotti monteil lula 3d pci usb2 firewire lybra 2 4 ceviz lettore dvd combo divx yeah testo occhi da orientale kit vivavoce veicolare senza fili astrium here j go agin dvp900sa fiat punto 90 sporting jabra bt250v samsung tv lcd canon dv mv880x testi gianni fiorellino cartina germania the village cinema hard disk usb2 250gb infrarossi cuffie italia sardegna vacanze non dirmelo ci credo leggi sulle pertinenze firmware lg u8180 ministero istruzione it modem esterno postcard from french riviera rapper italiano bassi maestro frigorifero ariston mtaa nerd dani bananinha mobile per plasma agordo cremona batteria motorola v525 baia san felice rockinrio lisboa mia st john playboy 1999 canzoni fascisti fotografava egitto sharm apple ibook 12 software per videochat die lustige witwe registratore telefono nokia 3650 red octobre www manzone com www a c calcio cesena it un magico natale tatoo per fondoschiena diabolico diffusori 5 1 sony warum blur barry ryan midi lettore cd 300 id sw cd1 lee ryan blue filmati erotici gratis thomson 42pb220s4 congelatori incasso a mortasatrice edinburgh quei fantastici pazzi volanti dlink ant240801 sd mp3 radio melissa ford valvola di non ritorno www braid pitt it tenacious d stufe nordica tour cattura r zero nero wolfe sfida al cioccolato super smash lcd vga essi vivono escort a milano uploading hex key ragazzi 18 10 anni in posa una donna in cerca di brividi linksys wireless scandiuzzi dimm 256mb lego football mania mp3 creative zen micro se 5gb silvi marina lucia olga tovar porsche boxster argento volkswagen golf 2 0 tdi sport impianto hi fi panasonic rapporto 1991 sull economia del home cinema dvd hotel kennedy roma sum 41 at ip download msn plus sigla telegiornale canale 5 flinders (fiume) colonna sonora titanic frigoriferi combinati a due motori s3 trio64v2 dx sigma 18125 dc ricetta riso w w w invoglia it ristoranti parma hard disk sata2 These while loops will calculate the Factorial of a number:

Visual Basic / QBasic

Dim counter as Integer : counter = 5
Dim factorial as Long : factorial = 1
While (counter > 0)
  factorial = factorial * counter     'Multiply
  counter = counter - 1               'Decrement
Print factorial                       'Prints out the result.


Dim counter as Integer = 5
Dim factorial as Integer = 1
While counter > 0
  factorial = factorial * counter     //Multiply
  counter = counter - 1               //Decrement
MsgBox Str( factorial )               // Prints out the result.

C or C

unsigned int counter = 5;
unsigned long factorial = 1;
while (counter > 0)
  factorial *= counter--; /*Multiply, then decrement.*/

printf("%i", factorial);

Recursive approach in C or C

unsigned long factorial(unsigned long f)
   if (f) return(f * factorial(f - 1))
   return 1;

printf("%i", factorial(5));


<HIGHLIGHTSYNTAX language="perl">

sub factorial {
    my $n = shift;
    my $f = 1;
    $f *= $n-- while $n > 0;    # Multiply, then decrement
    return $f;
sub recursive_factorial {
    my $n = shift;
    return $n * recursive_factorial($n - 1) if $n;
    return 1;
print factorial 5;
print recursive_factorial 5;


Tcl (Tool command language)

set counter 5
set factorial 1
while {$counter > 0} {
  set factorial [expr $factorial * $counter] 
  incr counter -1 
puts $factorial
proc factorial n {
  if {$n <= 0} {
    return 1
  } else {
    return [expr {$n * [factorial [expr {$n - 1}]]}]

Java, Csharp

The code for the loop is the same for Java and Csharp:

Note: if you intend to use the program to generate large factorials (such as 20!, 50! etc.) then you should store and return the factorial as a double rather than a long or int, due to the far greater size of double-precision values.

int counter = 5;
long factorial = counter;
while (counter > 1)
   factorial *= --counter; // Multiply the decremented number.

//!n = n*(n-1)

For Java the result is printed as follows:


The equivalent in C# is:


Rather than using a loop, use a recursive method:

     * A recursive factorial calculation method
     * @param n the number to be factored
     * @return the factorial of n
    public static int factorial(int n) {
        return ((n == 0) ? 1 : n * factorial(n - 1));


Example 1

 # let rec fact = function
     | 0 -> 1
     | n -> n * fact(n-1);;
 val fact : int -> int = <fun>

For example:

 # fact 5;;
 - : int = 120

Example 2

# let rec f n = if n=0 then 1 else n*f(n-1);;
val f : int -> int = <fun>

For example:

# f 5;;
- : int = 120


program Factorial
  Counter, Factorial: integer;
  Counter := 5;
  Factorial := 1;
  while Counter > 0 do begin
    Factorial := Factorial * Counter;
    Counter := Cou

2000 nter - 1;



import operator
def factorial(num):
    return reduce(operator.mul, range(1, num   1))


(define (fac n)
 (if (= n 0)
     (* n (fac (- n 1)))))
;give fac a value of 5
(fac 5)

Common Lisp

;;; This is tail recursive. Remember that tail-recursion optimization isn't
;;; enabled by default in most CL compilers and interpreters
(defun ! (n)
        ((fact1 (n m)
             (if (zerop n)
                 (fact1 (1- n) (* m n)))))
    (fact1 n 1)))

This is an optimized algorithm, you can find more about it and some other ways to increase its performance at [1].

(defun ! (n)
    (let ((shift 0))
        (labels ((fact1 (n m)
                        ((and (evenp n) (> m 1))
                            (incf shift (ash n -1))
                            (fact1 (ash n -1) (ash m -1)))
                        ((<= n m) n)
                        (t (* (fact1 n (ash m 1)) (fact1 (- n m)(ash m 1)))))))
        (ash (fact1 n 1) shift))))