# Probability that an odd number (given number of digits and ending number) is prime

**URL:** <https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981>\
**Category:** Factual Questions\
**Created:** [January 27, 2015, 4:41am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981 "2015-01-27T04:41:48Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![am77494](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@am77494](https://boards.straightdope.com/u/am77494)\
**Post date:** [January 27, 2015, 4:41am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/1 "2015-01-27T04:41:48Z")

</div>

Given a prime number of N digits and the end digit, is there a formula that predicts the probability that it is prime ? Also as N gets large, is the probability independent of the end digit ?  
(Potential nitpick avoidance : odd numbers ending with 5 are ignored for obvious reasons)

Here’s what I see with Excel

A\> Given a 2 digit number, the probability of it being prime when the ending digit is:  
a\> **1** = 0.56 or 5/9 (11, 31, 41, 61, 71)  
b\> **3** = 0.67 or 6/9 (13, 23, 43, 53, 73, 83)  
c\> **7** = 0.56 or 5/9 (17, 37, 47, 67, 97)  
d\> **9** = 0.56 or 5/9 (19, 29, 59, 79, 89)

B\> Given a 3 digit number, the probability of it being prime when the ending digit is:  
a\> **1** = 0.39 or 35/90  
b\> **3** = 0.39 or 35/90  
c\> **7** = 0.44 or 40/90  
d\> **9** = 0.37 or 33/90

B\> Given a 4 digit number, the probability of it being prime when the ending digit is:  
a\> **1** = 0.30 or 266/900  
b\> **3** = 0.30 or 268/900  
c\> **7** = 0.29 or 262/900  
d\> **9** = 0.29 or 265/900

---

<div class="post-metadata">

**Author:** ![robert\_columbia](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@robert\_columbia](https://boards.straightdope.com/u/robert_columbia)\
**Post date:** [January 27, 2015, 4:44am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/2 "2015-01-27T04:44:54Z")

</div>

[Proof that all odd numbers are prime](http://rationalwiki.org/wiki/Fun:Proof_that_all_odd_numbers_are_prime).

---

<div class="post-metadata">

**Author:** ![Jragon](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jragon](https://boards.straightdope.com/u/Jragon)\
**Post date:** [January 27, 2015, 4:52am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/3 "2015-01-27T04:52:28Z")

</div>

There are a number of things known about this (or can be derived) due to the [Prime number theorem](http://en.wikipedia.org/wiki/Prime_number_theorem).

> [@](#):
>
> Informally speaking, the prime number theorem states that if a random integer is selected in the range of zero to some large integer N, the probability that the selected integer is prime is about 1 / ln(N), where ln(N) is the natural logarithm of N. Consequently, a random integer with at most 2n digits (for large enough n) is about half as likely to be prime as a random integer with at most n digits.

This includes evens and multiples of 5, though.

Edit: I know this isn’t exactly what you want, but it’s a starting place for research on this topic. This also only really holds for large numbers.

---

<div class="post-metadata">

**Author:** ![The\_Joker\_and\_the\_Thief](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@The\_Joker\_and\_the\_Thief](https://boards.straightdope.com/u/The_Joker_and_the_Thief)\
**Post date:** [January 27, 2015, 5:09am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/4 "2015-01-27T05:09:07Z")

</div>

> [@am77494](#):
>
> Also as N gets large, is the probability independent of the end digit ?  
> (Potential nitpick avoidance : odd numbers ending with 5 are ignored for obvious reasons)

???

Any large number ending in 0,2,4,5,6, or 8 cannot be prime. The probability of a number being prime is highly dependent on its last digit.

---

<div class="post-metadata">

**Author:** ![Jragon](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jragon](https://boards.straightdope.com/u/Jragon)\
**Post date:** [January 27, 2015, 5:10am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/5 "2015-01-27T05:10:38Z")

</div>

> [@The\_Joker\_and\_the\_Thief](#):
>
> ???
> 
> Any large number ending in 0,2,4,5,6, or 8 cannot be prime. The probability of a number being prime is highly dependent on its last digit.

He was talking about if the only digits we’re considering are 1, 3, 7, or 9. Are they roughly evenly distributed among those four digits as N gets arbitrarily large?

---

<div class="post-metadata">

**Author:** ![The\_Joker\_and\_the\_Thief](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@The\_Joker\_and\_the\_Thief](https://boards.straightdope.com/u/The_Joker_and_the_Thief)\
**Post date:** [January 27, 2015, 5:29am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/6 "2015-01-27T05:29:28Z")

</div>

> [@Jragon](#):
>
> He was talking about if the only digits we’re considering are 1, 3, 7, or 9. Are they roughly evenly distributed among those four digits as N gets arbitrarily large?

Oh, whoops.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [January 27, 2015, 5:37am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/7 "2015-01-27T05:37:13Z")

</div>

The number of primes less than x is asymptotically x/ln(x). This is like a cumulative distribution, so the density of primes near x is the derivative of this or 1/ln(x) - 1/[ln(x)][sup]2[/sup]. As we’re dealing with asymptotics, we can ignore the second term. So the density of primes near x is 1/ln(x) or the density of primes near 10[sup]k[/sup] is 1/[k ln(10)] =0.4343/k.

But that’s for all integers near 10[/sup]k[sup]. Only those ending in 1 3 7 9 can be prime and those comprise 40% of the integers so the density of primes amongst k digit integers ending in 1 3 7 or 9 is about 1.08/k.

Are primes equally distributed amongst integers ending in 1 3 7 and 9. I’d be amazed if they aren’t, but I don’t know a proof off hand.

Sorry I see I bollixed up the formatting and I doubt I’ll fix it within five minutes.

---

<div class="post-metadata">

**Author:** ![Skald\_the\_Rhymer](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Skald\_the\_Rhymer](https://boards.straightdope.com/u/Skald_the_Rhymer)\
**Post date:** [January 27, 2015, 5:41am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/8 "2015-01-27T05:41:43Z")

</div>

> [@The\_Joker\_and\_the\_Thief](#):
>
> ???
> 
> Any large number ending in 0,2,4,5,6, or 8 cannot be prime. The probability of a number being prime is highly dependent on its last digit.

Numbers ending in 0, 2, 4, 5, 6, and 8 cannot be prime IN THE DECIMAL SYSTEM. But. If I may use a theological term, that is accident, not essence.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [January 27, 2015, 5:44am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/9 "2015-01-27T05:44:32Z")

</div>

> [@Skald\_the\_Rhymer](#):
>
> Numbers ending in 0, 2, 4, 5, 6, and 8 cannot be prime IN THE DECIMAL SYSTEM. But. If I may use a theological term, that is accident, not essence.

Numbers ending in 0 can’t be prime in any system based on an integer greater than 1 with the exception of 10 when the base is prime.

---

<div class="post-metadata">

**Author:** ![Skald\_the\_Rhymer](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Skald\_the\_Rhymer](https://boards.straightdope.com/u/Skald_the_Rhymer)\
**Post date:** [January 27, 2015, 11:58am UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/10 "2015-01-27T11:58:26Z")

</div>

> [@OldGuy](#):
>
> Numbers ending in 0 can’t be prime in any system based on an integer greater than 1 with the exception of 10 when the base is prime.

Your point being?

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 27, 2015, 5:00pm UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/11 "2015-01-27T17:00:00Z")

</div>

The point is that, in any base, there is at least one final digit which is significantly less likely to be prime.

One could go further and point out that, in any non-prime base (which is most of them), there are at least two such final digits.

---

<div class="post-metadata">

**Author:** ![md2000](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@md2000](https://boards.straightdope.com/u/md2000)\
**Post date:** [January 27, 2015, 5:06pm UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/12 "2015-01-27T17:06:28Z")

</div>

How the various professions prove all odd numbers are prime:

Mathematician: “3 is prime, 5=3+2 is prime,7=5+2 is prime… therefore by induction all odd numbers are prime.”

Physicist: “3 is prime, 5 is prime, 7 is prime, 9 - experimental error, 11 is prime,… therefore all odd numbers are prime.”

Engineer: “3 is prime, 7 is prime, 9 is prime, 11 is prime… all odd numbers are prime.”

---

<div class="post-metadata">

**Author:** ![robert\_columbia](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@robert\_columbia](https://boards.straightdope.com/u/robert_columbia)\
**Post date:** [January 27, 2015, 6:14pm UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/13 "2015-01-27T18:14:54Z")

</div>

> [@md2000](#):
>
> How the various professions prove all odd numbers are prime:
> 
> Mathematician: “3 is prime, 5=3+2 is prime,7=5+2 is prime… therefore by induction all odd numbers are prime.”
> 
> Physicist: “3 is prime, 5 is prime, 7 is prime, 9 - experimental error, 11 is prime,… therefore all odd numbers are prime.”
> 
> Engineer: “3 is prime, 7 is prime, 9 is prime, 11 is prime… all odd numbers are prime.”

Attorney: “Nine may or may not be prime, depending on the witnesses’ testimonies and the physical evidence furnished.”  
Attorney: “According to Smith v. Jones, 9 was judicially declared prime.”  
Politician: “For a sufficient donation, 9 can be reclassified.”  
Windows Programmer: “3 is prime. 5 is prime. 7 is prime. This program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor.”  
Statistician: “100% of the sample 5, 13, 37, 41 and 53 is prime, so it looks like it’s probably true that all odd numbers are prime.”  
IT Support Representative: “We haven’t received any reports of non-prime odd numbers. Have you upgraded to the latest version of our product?”  
Diversity Coordinator: “Why don’t we ask 9 what it wants to be?”  
ISIS Member: “You have 72 hours to make 9 prime again. If not, we will behead your math teacher.”  
Mormon: “9 is prime, the spirit tells me it’s true.”  
Homeopath: “If you dilute it enough, 9’s primal nature comes out. Come see the light.”

---

<div class="post-metadata">

**Author:** ![Itself](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@Itself](https://boards.straightdope.com/u/Itself)\
**Post date:** [January 27, 2015, 6:23pm UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/14 "2015-01-27T18:23:36Z")

</div>

> [@am77494](#):
>
> Also as N gets large, is the probability independent of the end digit ?

Yes, by Dirichlet’s theorem. (I’m assuming you’re restricting to the case where that digit is 1, 3, 7, or 9. I’m also avoiding specifying formally exactly how those probabilities are defined.)

---

<div class="post-metadata">

**Author:** ![Itself](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@Itself](https://boards.straightdope.com/u/Itself)\
**Post date:** [January 27, 2015, 8:50pm UTC](https://boards.straightdope.com/t/probability-that-an-odd-number-given-number-of-digits-and-ending-number-is-prime/710981/15 "2015-01-27T20:50:52Z")

</div>

I should also point out that this statement isn’t obvious or even necessarily expected. By Dirichlet’s theorem, primes that are +1 mod 4 versus -1 mod 4 have the same asymptotic density. On the other hand, if you count the primes below some fixed N that are +1 mod 4 versus those that are -1 mod 4, the latter exceed the former “most of the time.” (I’m deliberately avoiding making the bit in quotes formal, but hopefully the general idea is clear from context.)
