Problem with exponent of p in n! algorithm (was: a(27) new higher lower bound)
Max
relf at unn.ac.ru
Wed Nov 23 01:17:26 CET 2005
Alonso Del Arte wrote:
> David, there is a problem with the algorithm
>
> int e(int p, int n) {
> int s = 0;
> while (n > 0) {
> n /= p; // That is, n = floor(n/p)
> s += n;
> }
> return s;
> }
>
> I implemented in Mathematica thus:
>
> expoPF[p_, n_] := Module[{s, x}, x =
> n; s = 0; While[x > 0; x = Floor[x/p]]; s = s + x; s]
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]
Max
More information about the SeqFan
mailing list