Math Games

Evil Numbers

Ed Pegg Jr. and Chris Lomont, October 4, 2004

This calls for wisdom. If anyone has insight, let them calculate the number of the beast, for it is man's number. His number is 666. (Revelations 13:18)

The number 666 pops up a lot in recreational mathematics. Mike Keith has a whole page devoted to this number of the beast. Among the many tidbits recorded by Mike are the following:

Many of these items are also listed at the Beast Number entry for MathWorld. Ilan suggested the last item be added. Both pi and phi, π and φ, could be considered evil numbers. Evil numbers have the despicable property that if the digits following the decimal point are added one at a time, 666 will be hit exactly. It's like the game of 21, where you want to hit 21, without going over.

How common are evil numbers? This actually turns out to be a nice puzzle, which I put on (and answer below -- stop reading now if you wish to solve this on your own). There are 905 constants listed at the back of Steven Finch's marvelous book Mathematical Constants -- how many of them would be needed to make the list of evil constants complete? How much of a can of worms would it be to list all the evil constants?

A few additional evil constants were found in a search:

One can also sum the numbers in the continued fraction expansion.

Evil numbers are easy to find, as one might expect with an arbitrarily defined property. Interestingly, π is doubly evil. Many numbers aren't evil. For example, e isn't evil. The important sums are 665 and 668 after 141 decimal digits -- e goes over 666 without hitting it. Chris Lomont notes that you can take every 15th digit of e, and show that e is somewhat evil. The farthest he had to reach for any constant was with Catalan's constant, which wasn't evil until he took every 28th digit.

It appears that most numbers are at least somewhat evil. With enough fiddling, almost anything is likely to be findable.

How common are evil numbers? (number of non-zero digits / sum of digits) gives a good estimate. For a base 10 number, the estimate gives 9/(1+2+3+4+5+6+7+8+9) = 20% = 1/5. Thus, any random number has a 1 in 5 chance of having this property.

A fifth is an estimate. Chris Lomont found a recursion that could give an exact value:

p[1] = 1/9;
p[k_ /; k <10] := p[k] = 1/9 + 1/9 Sum[p[j], {j, 1, k - 1}];
p[k_ /; k > 9] := p[k] = 1/9 Sum[p[k - d], {d, 1, 9}];
Timing[Table[p[100 n], {n, 1, 10}]][[1]]

The exact probability of 666 being hit is the following:

179299063538588479967204114608449603102519994141366640807202899019238235033002199785195257797538993376610275501957173900000 /

Which is approximately .2000000000000000000000000000000000000000000000000000000000000002166222683713523944720537405934866672. That's very close to 1/5. The third term in the continued fraction expansion of p[666] is 184653222869167741981875869102352405779668736930185085305398884.

The probability of evilness converges quickly to 1/5, but it does so in a highly oscillatory way. Note that each term is being multiplied by 1.243n.

Figure 1. ListPlot[Table[(1/5 - p[n]) (1243/1000)^n, {n, 30, 900}]]

Another method Chris Lomont discovered for calculating evilness involved the series expansion of (1-t9)/(t10-10t+9). In this series expansion, coefficients n is identical to p[n].

It seemed like there should be a closed form for all of this, but it was beyond Chris's ability to calculate. Also, I wasn't able to calculate the evilness probability for the continued fraction of a random irrational number. This calls for wisdom. If anyone has insight, let them calculate the equations.


Steven Finch, Mathematical Constants, Cambridge University Press, 2003.

Xavier Gourdon, "Constants and Records of Computation",

Mike Keith, "The Number of the Beast",

Chris Lomont, "Angelic and Evil Numbers",

Eric W. Weisstein. "Beast Number, Bloch Constant, Catalan's constant, Continued Fraction, Cube Line Picking, Euler Totient Function, Gauss Constant, Glaisher-Kinkelin Constant, Golden Ratio, Hard Hexagon Entropy Constant, Pi, Pi Continued Fraction, Pi Digits, Ramanujan Constant, Stieltjes Constants, " From MathWorld--A Wolfram Web Resource.

Math Games archives.

Comments are welcome. Please send comments to Ed Pegg Jr. at

Ed Pegg Jr. is the webmaster for He works at Wolfram Research, Inc. as an associate editor of MathWorld, and as administrator of the Mathematica Information Center.