Subject: Problem with exponent of p in n! algorithm (was: a(27) new higher lower bound)

Dean Hickerson dean at math.ucdavis.edu
Fri Nov 25 09:54:47 CET 2005


Alonso Del Arte wrote:

> David, there is a problem with the algorithm
...
> expoPF[p_, n_] := Module[{s, x}, x =
>    n; s = 0; While[x > 0; x = Floor[x/p]]; s = s + x; s]

Max replied:

> I'm not familiar with Mathematica, but it seems to me that you closed
> While-loop at a wrong place. It should be
>
> expoPF[p_, n_] := Module[{s, x}, x =
>      n; s = 0; While[x > 0; x = Floor[x/p]; s = s + x]; s]

That's part of the problem.  Also, the first semicolon inside the While
should be a comma.  The stuff before the comma is the condition that's
tested each time through; the stuff after is a list of statements separated
by semicolons.  So:

expoPF[p_, n_] := Module[{s, x}, x =
     n; s = 0; While[x > 0, x = Floor[x/p]; s = s + x]; s]

Dean Hickerson
dean at math.ucdavis.edu





More information about the SeqFan mailing list