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 0For 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
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers26
Suggested Problems
-
Flip the main diagonal of a matrix
905 Solvers
-
Sum of first n terms of a harmonic progression
500 Solvers
-
Flag largest magnitude swings as they occur
690 Solvers
-
18159 Solvers
-
Matrix multiplication across rows
397 Solvers
More from this Author323
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
The comment "For example, five primes less than 100 end in a 1 (11, 31, 61, 71, and 91)" should read "For example, five primes less than 100 end in a 1 (11, 31, 41, 61, and 71)". 91 is not a prime.