On Sun, Jul 31, 2005 at 02:26:47PM +0100, Jason Clements wrote:
> er... why not
> Digits = Length((string)Number) ?
>
> or is this too fiendishly complicated ?
1. It requires a language with native support for bignums (or rewriting the
expression into using a bignum library).
2. It is dead slow, having to actually calculate the entire number (in our
case, often tens of millions of digits) just to get its length.
The formula probably wasn't intended for directly plugging into a programming
language, more like a mathematical formula. As the context of this list is
Mersenne primes, usually “number” would be of the form 2^n-1, so you'd get:
d = ceil(log10(p))
= ceil(log10(2^n - 1))
= ceil(log10(2^n)) (assuming n is an integer >= 1)
= ceil(n * log10(2))
So, by using simple logarithm rules you avoid the need to write the order out
altogether; just a multiplication by a constant and a ceil.
/* Steinar */
--
Homepage: http://www.sesse.net/
_______________________________________________
Prime mailing list
[email protected]
http://hogranch.com/mailman/listinfo/prime