e-Prime

Author

Eric W. Weisstein
October 11, 2010

This notebook downloaded from http://mathworld.wolfram.com/notebooks/PrimeNumbers/e-Prime.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/e-Prime.html.

©2010 Wolfram Research, Inc. except for portions noted otherwise

Starting with 2.71...

EPrime[n_]:=ToExpression["2"<>StringTake[ToString[N[E,n+2]],{3,n+1}]]

Enumeration

With[{n=10^3},Select[ToExpression[Reverse[NestList[StringDrop[#,-1]&,"2"<>StringTake[ToString[N[E,n+2]],{3,n+1}],n-1]]],PrimeQ]
]//Timing

Position

With[{n=2 10^3},Position[ToExpression[Reverse[NestList[StringDrop[#,-1]&,"2"<>StringTake[ToString[N[E,n+2]],{3,n+1}],n-1]]],_?PrimeQ]
]//Flatten//Timing

With[{n=5 10^3},Position[ToExpression[Reverse[NestList[StringDrop[#,-1]&,"2"<>StringTake[ToString[N[E,n+2]],{3,n+1}],n-1]]],_?PrimeQ]
]//Flatten//Timing

Check

l={1,3,7,85,1781,2780,112280,155025};

EPrime[155025]//IntegerLength

Do[
Print[{i,IntegerLength[EPrime[l[[i]]]],PrimeQ[EPrime[l[[i]]]]//Timing}],
{i,Length[l]}
]

Floor e-Primes

Block[{$MaxExtraPrecision=10^6},l=Position[Floor[E^Range[10^3]],_?PrimeQ]//Flatten]//Timing

Block[{$MaxExtraPrecision=10^6},Floor[E^l]]

(l=Position[Floor[E^Range[10^4]],_?PrimeQ]//Flatten)//Timing

(l=Position[Floor[E^Range[10^5]],_?PrimeQ]//Flatten)//Timing

Ceiling e-Primes

Block[{$MaxExtraPrecision=10^6},l=Position[Ceiling[E^Range[10^3]],_?PrimeQ]//Flatten]//Timing

Block[{$MaxExtraPrecision=10^6},Ceiling[E^l]]

(l=Position[Ceiling[E^Range[10^4]],_?PrimeQ]//Flatten)//Timing

(l=Position[Ceiling[E^Range[10^5]],_?PrimeQ]//Flatten)//Timing

First occurrence of n-Digit prime starting anywhere

d=First[RealDigits[E,10,1000]];

Allowing leading 0s

pos=Flatten[Position[FromDigits/@Partition[d,#,1],_?PrimeQ,1,1]&/@Range[10]]

primes=FromDigits/@MapIndexed[Take[d,#1+{0,Last[#2]-1}]&,pos]

PrimeQ[primes]

Length/@IntegerDigits/@primes

Disallowing leading 0s

pos=Function[n,Position[Partition[d,n,1],_?(First[#]>0&&PrimeQ[FromDigits[#]]&),1,1,Heads->False]]/@Range[70]//Flatten

pos-1

Take[primes=FromDigits/@MapIndexed[Take[d,#1+{0,Last[#2]-1}]&,pos],20]

And@@PrimeQ[primes]

Range[Length[primes]]==Length/@IntegerDigits/@primes