69

Suppose for the purpose of this question that number $1$ is a prime number.

Consider the prime number $311$. If we remove one $1$ from the number we arrive at the number $31$ which is also prime. If we removed $3$ instead of $1$ we would arrived at the number $11$ which is prime. If we remove $3$ from the number $31$ we arrive at the prime number $1$ and if we remove $1$ from $31$ we arrive at the number $3$ which is prime. And if we removed number $1$ from the number $11$ we would arrive at the prime number $1$.

So what property does this number $311$ have?

It has the property that if we remove one digit in any way we want we arrive at the prime number and if we remove two digits in any way we want we also arrive at the prime number. (Of course, if the original prime number had $n$ digits then it should be prime whatever $k$ digits we remove, for $1\le k\le n-1$.)

The question would be:

Are there an infinite number of prime numbers so that removing any number of digits leaves us with a prime number?

It seems to me that big enough prime numbers will rarely have the property that for every possible removal of some of the digits we will arrive at the prime number, but I see no reason that forbids an infinite number of these prime numbers.

Teepeemm
  • 723
  • 5
  • 12
Farewell
  • 4,900
  • 1
  • 15
  • 32
  • Are you removing digits just from the ends, or possibly from the middle? – Théophile May 01 '16 at 16:00
  • Similar Question: http://math.stackexchange.com/questions/33094/deleting-any-digit-yields-a-prime-is-there-a-name-for-this. – S.C.B. May 01 '16 at 16:00
  • @Théophile Not just from the ends but in any way you want. – Farewell May 01 '16 at 16:01
  • @MXYMXY Thanks, I did not see that question before, should I delete my question because there is a similar one on the site? – Farewell May 01 '16 at 16:02
  • @Farewell Well, it's still different slightly..I don't know. – S.C.B. May 01 '16 at 16:03
  • @MXYMXY Yes, it is different, Maybe better that my question stays on the site, – Farewell May 01 '16 at 16:04
  • @MXYMXY In question you linked it seems that there are considered primes which stay primes with only one digit removal. – Farewell May 01 '16 at 16:06
  • 10
    Infinitely many seems very doubtful, since almost all the digits have to be $3$. – André Nicolas May 01 '16 at 16:07
  • @AndréNicolas Do you know of any larger than 311? – Farewell May 01 '16 at 16:09
  • 7
    If there is a $5$ there, it has to be the most significant digit. – Arthur May 01 '16 at 16:14
  • 1
    @Arthur We can also eliminate places where 2 can be. – Farewell May 01 '16 at 16:15
  • 65
    As a side note, $1$ is not prime – Stella Biderman May 01 '16 at 16:24
  • The largest such number seems to be $317$. – Travis Willse May 01 '16 at 16:45
  • @Travis Haha. I really did not expect (in the moment of writing the question) that there is just a few of them. – Farewell May 01 '16 at 16:48
  • 5
    Using @AndréNicolas' solution, we can carry this out by hand. If $2$ or $5$ is not the leading digit, the only possible digits are $1, 3, 7$. Since we cannot repeat $3$ or $7$ (as we could produce $33$ or $77$), the only $3$-digit possibilities that start with $7$ are $731, 713, 711$, but all of these are composite. The leading digit cannot be $5$, as $51, 57$ are composite and $533$ has two $3$'s. Finally, $371$ is composite, bringing us to $317$. – Travis Willse May 01 '16 at 16:52
  • I remember some years ago when doing the mathematical olympics for my province a problem asked how many such numbers exist... – Bakuriu May 02 '16 at 11:40
  • You may be interested in the Wikipedia article on [truncatable primes](https://en.wikipedia.org/wiki/Truncatable_prime) although I don't think any of the results mentioned there consider $1$ as a prime number. – bof May 10 '16 at 23:57

5 Answers5

125

It is clear that we cannot have digits $0,4,6,8,9$ in those prime numbers. There can be at most one $2$ because $22$ is composite,, at most one $3$ because $33$ is composite,at most one $5$ because $55$ is composite, at most one $7$ because $77$ is composite, at most two $1$`s because $111$ is composite, so such prime number can have at most $6$ digits so there is a finite number of such prime numbers.

Farewell
  • 4,900
  • 1
  • 15
  • 32
  • 5
    More over, the $2$ should be the first digit from the left. Otherwise after removing the digits to the right of the $2$, we could always arrive at an even number. – Aritra Das May 01 '16 at 17:04
  • 3
    Similar argument holds for $5$ – Aritra Das May 01 '16 at 17:06
  • 1
    @AritraDas Yes I know, thanks. – Farewell May 01 '16 at 17:26
  • 6
    Farewell: you know that, but the reader that arrived here and read your answer didn't. @AritraDas is improving on your answer. – Mindwin May 02 '16 at 20:04
  • 4
    @Mindwin, no, the question was whether there are an infinite number, and this answer suffices as is to show there are not. Nothing needs to be added, and no addition (among the ones mentioned) will improve it. – msh210 May 03 '16 at 00:43
  • 6
    Technically there should be zero "1" because 1 is not prime thus allowing the number to degenerate into 1 would render it a non-prime. – slebetman May 03 '16 at 07:22
  • 15
    @slebetman: "technically" you should read the question, which states very clearly that 1 *is* to be considered "prime" for the purposes of the question. Mathematics has the absolute right to define notation, and everywhere in this question and its answers, "prime" means "prime or equal to 1" ;-p – Steve Jessop May 03 '16 at 10:02
82

To build on the earlier answers, there are exactly twenty such numbers, and they are:

1, 2, 3, 5, 7, 11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131, 137, 173, 311, 317

As can be found by the following program, which is correct as per Farewell's argument that seven digit and longer numbers cannot have the given property:

import gmpy

def test(n):
    if (not gmpy.is_prime(n)) and n != 1:
        return False
    s = str(n)
    if len(s) == 1:
        return True
    for i in xrange(len(s)):
        if not test(int(s[:i] + s[i+1:])):
            return False
    return True

print filter(test, xrange(10000000))

It is further worth noting that this program's output list is clearly exhaustive even barring Farewell's argument; the moment we fail to find any four digit examples we exclude the possibility of five digit (or longer) examples, as they must include four digit examples as substrings.

WroteAProgram
  • 829
  • 5
  • 2
  • 2
    The program is elegant, and ironically fitting given your username. But can you also give a (preferably set theoretic) conceptual explanation of why this is the case, rather than just a pseudo-proof that it IS the case? – Max von Hippel May 01 '16 at 22:06
  • 26
    Here starts the debate on whether computer-verification counts as proof. (I vote "yea".) – Daniel R. Collins May 01 '16 at 22:08
  • 3
    @MaxvonHippel: Why do you presuppose that there *is* a good conceptual explanation? Perhaps, since this had to be a finite set, those twenty numbers "just happened" to be the ones that fit the requirements. – Kevin May 02 '16 at 00:07
  • I think there always is a conceptual explanation, at least in number theory. That doesn't mean there is one which we know of or can easily articulate, but for something as pattern driven as this sort of question, I think it's unlikely there is not some conceptual driver. Were I to invest time in investigating this, I would probably try looking at the problem in non module-10 systems (roughly speaking, you know what I mean) and look for a universal pattern. I'm a CS guy though, not a mathematician, so don't assume I speak with much real authority :) – Max von Hippel May 02 '16 at 00:18
  • 8
    @MaxvonHippel: Number theory (and anything to do with the intrinsic nature of natural numbers as opposed to reals) is the **last** place where you expect to find conceptual explanations. For example, find all positive integer solutions $(x,y)$ satisfying $x^3 + 3 = y^7$... To clarify, this does not mean that there is never a conceptual explanation, but that one should not expect it by default. – user21820 May 02 '16 at 03:25
  • 1
    Is that code an actual program in some language? Seems weird :-p. – YoTengoUnLCD May 02 '16 at 03:50
  • @user21820 good to know! I'm taking more higher level maths next year and look forward to learning more about it. – Max von Hippel May 02 '16 at 04:09
  • 12
    @YoTengoUnLCD: Looks like Python to me. – user21820 May 02 '16 at 04:35
  • 1
    None of the three-digit examples survives if we decide to disallow the number $1$ as a prime number. – Jeppe Stig Nielsen May 02 '16 at 08:25
  • 11
    Your sequence is a subsequence of [OEIS A068669](http://oeis.org/A068669) (where they have the weaker requirement that all substrings (i.e. consecutive strings of figures) are non-composite). A068669 has twenty-four members. – Jeppe Stig Nielsen May 02 '16 at 08:31
  • 2
    @MaxvonHippel Actually it follows almost directly from the definition, that if there are no such numbers with four digits, there cannot exist any with more than four digits either. – kasperd May 02 '16 at 09:33
  • 3
    @DanielR.Collins All that a computer assisted proof is lacking from turning it into a "real" proof is proofs of intermediate results of the form: Running program $P$ on input $X$ yields output $Y$. Each of those can be trivially proven by showing a transcript of the program execution. It's not particular productive to include such a transcript in a paper, so I agree with you. – kasperd May 02 '16 at 09:52
  • 1
    @MaxvonHippel It's not really a natural question, so I don't think there is necessarily a nice explanation that isn't just a computation. – Spooky May 02 '16 at 19:27
  • @Spooky But we did it, since the question is a yes/no/unprovable problem, not find every single special prime that satisfies. We did that too, just to be safe though, you know? – Simply Beautiful Art May 03 '16 at 00:17
49

There are only finitely many, indeed there are none with more than $3$ digits. Clearly our prime cannot have $0$ as a digit.

If our prime has $4$ or more digits, and has $2$ or more not equal to $3$, we can by deleting one or two get a number greater than $3$ with digit sum divisible by $3$.

And if there are two or more $3$'s we can produce $33$.

André Nicolas
  • 491,093
  • 43
  • 517
  • 948
  • 1
    @Farewell "_Use comments to ask for more information or suggest improvements. Avoid comments like "+1" or "thanks"._" Literally. I suggest the improvement that you guys read what the comment box say. :P – pipe May 04 '16 at 12:42
32

Extending André's answer and Travis's comment:

Firstly, a 0 digit is ruled out since by definition it cannot be the first digit, and in any other position we could delete everything that follows it to leave a multiple of 10. All of which are composite since 10 is.

With 0 excluded, every digit must be prime (1, 2, 3, 5, 7) because we could delete everything else to leave a one-digit number. Note in particular that if a digit is 0 modulo 3 then it is 3.

With four or more digits, two of them are equal modulo 3 by the Pigeonhole Principle. Taking the digits modulo 3, we must have either:

  • Two 0s, that is to say two 3s. But then by deleting all other digits we have 33, which is not prime.

  • Two 1s (mod 3). Consider any two of the other digits. Either they are both 0 mod 3 (which is the above case); or else one of them is a 1 (so we can form a three-digit number whose digits are all 1 mod 3 and therefore with digit sum divisible by 3 and hence which is composite); or else one of them is a 2 (in which case we can form a two-digit number with a 1 and a 2 and hence which is composite).

  • Two 2s (mod 3). Same as above, with 1 and 2 reversed.

So solutions have at most three digits. For three-digit numbers, we can't have a 2 or a 5 after the first digit because $x2$ and $x5$ are divisible by 2 or 5 respectively. So digits after the first are taken from 1, 3, 7. Consider the first digit:

  • 7: Then the other two digits can't be 7 again, leaving us combinations of 1 and 3. They can't both be 1 (that's 3 digits all 1 mod 3), and they can't both be 3 (that's two 3s), leaving $713 = 23 \times 31$ and $731 = 17 \times 43$. No solutions.

  • 5: 51, and 57 are composite, so there are no 1s or 7s, leaving 533 (which is two 3s). No solutions.

  • 3: We can't have another 3, leaving combinations of 1 and 7. 377 has a repeated 7; $371 = 7 \times 53$; but $311$ and $317$ are both solutions. Hence $317$ is the largest solution.

  • 2: 21 and 27 are composite, leaving only 3, which we can't repeat. No solutions.

  • 1: The other two digits are combinations of 1, 3, 7. All three digits can't be 1 mod 3 (see above), so one of the digits must be a 3. But not both. The other digit is a 1 or a 7. This gives $113$, $131$, $137$, $173$ which are all solutions.

Consider 2 digit numbers if you can be bothered. Just pick out the primes consisting of two prime digits.

Finally, the 1-digit primes 1, 2, 3, 5, 7 are all solutions of course.

Steve Jessop
  • 4,046
  • 15
  • 21
  • Ingenious solution. Just want to ask you what inspired to you pick mod 3 from the start? Was it trial and error? – Hans May 24 '16 at 19:52
  • @Hans: because it's a question about digits and divisibility. When you're looking at base 10 digits it's quick to rule out a lot of non-primes by considering divisibility by 2 (i.e. is the last digit even) and divisibility by 3 (i.e. is the digit sum 0 mod 3). – Steve Jessop May 24 '16 at 21:30
11

I thought about what happens in bases b other than b = 10.

We cannot have the digit zero, or any digit that is a composite number (for example in hexadecimal: 4, 6, 8, 9, 10, 12, 14, 15). The possible digits are the number 1 and the primes p < b.

No digit other than 1 can appear more than once, since xx = x * 11 in every base. The digit 1 can appear at most three times, since 1111 = 11 * 101 in every base.

If the base b is odd, then a number de is even if d and e are both odd, so a solution x cannot contain two odd digits. The best we can ask for is 2d or d2 where d is an odd prime or 1.

Otherwise the base b is 6k, 6k+2, or 6k+4. If b = 6k+4 then x modulo 3 equals the sum of the digits, modulo 3. A solution x cannot contain both digits d = 1 (modulo 3) and digits d = 2 (modulo 3). It also cannot contain exactly three digits d = 1 or 2 (modulo 3). The largest possible solution has 3 digits, with one digit = 3, and the other two being equal (modulo 3). This case includes b = 10 (decimal numbers), so four or more digit solutions are impossible.

If b = 6k + 2, then for x = de we have x modulo 3 = (e - d) modulo 3. Therefore a solution x cannot have two digits that are the same (modulo 3). The largest possible solution has 3 different digits, with the first or the last digit = 3, and the other two being different (modulo 3).

The remaining case is b = 6k, where we can have at most three 1s, plus one of each prime < b. A digit 2 or 3 would have to be the first digit because d2 is divisible by 2 and d3 is divisible by 3 for any digit d. The number of digits in a solution x is therefore strongly limited, but I can't find any simple evidence that limits the number of digits.

In practice, if you take a five digit number x, there are ten 2-digit numbers, ten 3 digit numbers, five 4 digit numbers and one 5 digit number that would have to be primes, which is quite unlikely. And as the base b gets bigger, it gets more unlikely to find that many primes.

PS. I wrote a program systematically examining bases b up to about 4,000. There are thousands of four digit solutions. I found two five digit solutions: In base 12, 511b7 (b = 11) is a prime, and removing any digit or digits leaves a prime or the digit one. And in base 2730, the same for the five digit number (1)(1)(1423)(829)(631).

It looks like in base 2730 = 2 * 3 * 5 * 7 * 13, numbers where the last digit is a prime are primes much more often than in other bases.

Since a six digit solution requires several five digit solutions (at least four if the six digit solutions has three 1s and more if there are fewer 1s) for the same base b, and I found only two five digit solutions in total, a solution would be hard to find.

It's easy to show that if b is not a multiple of five, then for every six digit number x, that number or one of the numbers created by removing one to four digits is divisible by five. So to find a six digit solution, the base b must be a multiple of 30.

The chance that a random number x is prime is about 1 / ln x. But if we know that x is not divisible by 2, 3, or 5, then the chance is 3.75 / ln x. For x to be a six digit solution, the number x, plus six 5-digit, fifteen 4 digit, twenty 3-digit and fifteen 2-digit numbers must be prime. If we pick x where no digit is 2, 3, or 5, the chances for all these numbers to be prime is

$3.75^{57} / (ln p^6) / (ln p^5)^6 / ... / (ln p^2)^{15})$

or

$(3.75/ ln p)^{57} / (6 * 5^6 * 4^{15} * 3^{20} * 2^{15})$

On the other hand, the number of six digit numbers with all digits prime is about $(p / ln p)^6$. We can expect one solution x if the product is about 1. That's the case if the base is about b = 3.5 x $10^{15}$. At that point there are about $10^{85}$ six digit base-p numbers with all digits primes or 1. I don't think such a solution will ever be found.

gnasher729
  • 8,131
  • 16
  • 33
  • In a base divisible by $2 \times 3 \times 5 \times 7 \times 13$, if the last digit is a prime other than $2, 3, 5, 7$ or $13$, you don't need to worry about divisibility by $2$, $3$, $5$, $7$ or $13$; that rules out a lot of composites... – Robert Israel May 06 '16 at 22:13
  • Good, but you probably shouldn't use $b$ for both an odd digit and the base. – dejongbrent May 07 '16 at 20:20