Problem 45994. Investigate the frequency of last digits of prime numbers

The last digit of a prime number greater than 5 can be 1, 3, 7, or 9. If the primes are distributed randomly, then these digits should be equally likely. However, mathematicians discovered relatively recently that--as Robert Lemke Oliver put it--these digits "really hate to repeat themselves". In other words, last digits repeat less often than expected.

For example, five primes less than 100 end in a 1 (11, 31, 61, 71, and 91), and none of them are followed by a prime ending in a 1. In fact, none of the primes less than 100 and ending in 3, 7, or 9 are followed by a prime ending in 3, 7, or 9, respectively.

Write a function to compute the frequency of the last digits of primes between 7 and the input number. Return a matrix whose rows correspond to the digits of the first prime and columns correspond to the digits of the next prime. Please remember to (a) omit 2, 3, and 5 and (b) account for the prime following the last prime in your list. For the example given above, the function should return

         0    0.6000    0.4000         0
         0         0    0.3333    0.6667
    0.6667    0.1667         0    0.1667
    0.4000    0.4000    0.2000         0

For example, six primes less than 100 end in 7. They are followed by four primes ending in 1 (including 101), one prime ending in 3, zero primes ending in 7, and one prime ending 9. The frequencies, reported in the third row, are thus 2/3, 1/6, and 1/6.

Solution Stats

64.29% Correct | 35.71% Incorrect
Last Solution submitted on Mar 27, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

Suggested Problems

More from this Author265

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!