A252996 Magnanimous numbers: numbers such that the sum obtained by inserting a "+" anywhere between two digits gives a prime.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 14, 16, 20, 21, 23, 25, 29, 30, 32, 34, 38, 41, 43, 47, 49, 50, 52, 56, 58, 61, 65, 67, 70, 74, 76, 83, 85, 89, 92, 94, 98, 101, 110, 112, 116, 118, 130, 136, 152, 158, 170, 172, 203, 209, 221, 227, 229, 245, 265, 281, 310, 316, 334, 338, 356
Offset: 1
Examples
245 is in the sequence because the numbers 2 + 45 = 47 and 24 + 5 = 29 are both prime. See the first comment for the single-digit terms.
Links
- Robert G. Wilson v, Table of n, a(n) for n = 1..571
- Hans Havermann, in reply to Eric Angelini, Insert "+" and always get a prime, Dec 2014
- Giovanni Resta, magnanimous numbers, 2013.
- Carlos Rivera, Puzzle 401. Magnanimous primes, 2007, The Prime Puzzles & Problems Connection.
Programs
-
Maple
filter:= proc(n) local d; for d from 1 to ilog10(n)-1 do if not isprime(floor(n/10^d)+(n mod 10^d)) then return false fi od: true end proc: select(filter, [$0..10^5]); # Robert Israel, Dec 25 2014
-
Mathematica
fQ[n_] := Block[{idn = IntegerDigits@ n, lng = Floor@ Log10@ n}, Union@ PrimeQ@ Table[ FromDigits[ Take[ idn, i]] + FromDigits[ Take[ idn, -lng + i -1]], {i, lng}] == {True}]; (* or *) fQ[n_] := Block[{lng = Floor@ Log10@ n}, Union@ PrimeQ[ Table[ Floor[n/10^k] + Mod[n, 10^k], {k, lng}]] == {True}]; fQ[2] = fQ[3] = fQ[5] = fQ[7] = True; Select[ Range@ 500, fQ] (* Robert G. Wilson v, Dec 26 2014 *) mnQ[n_]:=AllTrue[Total/@Table[FromDigits/@TakeDrop[IntegerDigits[n],i],{i,IntegerLength[n]-1}],PrimeQ]; Join[Range[0,9],Select[Range[ 10,400], mnQ]] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, May 26 2017 *)
-
PARI
is(n)={!for(i=1,#Str(n)-1,ispseudoprime([1,1]*(divrem(n,10^i)))||return)} t=0;vector(100,i,until(is(t++),);t)
-
Python
from sympy import isprime def ok(n): s = str(n) return all(isprime(int(s[:i])+int(s[i:])) for i in range(1, len(s))) print([k for k in range(357) if ok(k)]) # Michael S. Branicky, Oct 14 2024
Comments