Weakly Prime

Author

Eric W. Weisstein
March 13, 2009

This notebook downloaded from http://mathworld.wolfram.com/notebooks/PrimeNumbers/WeaklyPrime.nb.

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

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

Enumeration

No restriction

Candidates[n_]:=Block[{d},FromDigits/@Flatten[MapIndexed[Outer[List,Sequence@@ReplacePart[List/@d,#2[[1]]->Complement[Range[0,9],{#}]]]&,d=IntegerDigits[n]],Length[d]]]

WeaklyPrimeQ[n_]:=PrimeQ[n]&&Not[PrimeQ/@(Or@@Candidates[n])]

Select[Range[10^4],WeaklyPrimeQ]//Timing

Select[Range[10^5],WeaklyPrimeQ]//Timing

Select[Range[10^6],WeaklyPrimeQ]//Timing

Select[Range[10^7],WeaklyPrimeQ]//Timing

WeaklyPrimeQ[929573]

Restriction that initial digit cannot be a 0

Candidates2[n_]:=Block[{d},FromDigits/@Flatten[MapIndexed[Outer[List,Sequence@@ReplacePart[List/@d,#2[[1]]->Complement[Range[If[#2[[1]]===1,1,0],9],{#}]]]&,d=IntegerDigits[n]],Length[d]]]

WeaklyPrimeQ2[n_]:=PrimeQ[n]&&Not[PrimeQ/@(Or@@Candidates2[n])]

Select[Range[10^6],WeaklyPrimeQ2]//Timing

Select[Range[10^7],WeaklyPrimeQ2]//Timing

WeaklyPrimeQ2[929573]