Find the number of seven-digit natural numbers whose decimal notation contains at least two adjacent digits that are prime numbers.
Solution:
The prime digits are [tex]2, 3, 5, 7[/tex] (four digits); the other six digits [tex]0, 1, 4, 6, 8, 9[/tex] are not prime. There are [tex]9\times 10^6=9\,000\,000[/tex] seven-digit numbers, so we count the complement: the numbers in which no two adjacent digits are both prime.
For [tex]k=1, 2, \ldots, 7[/tex] let [tex]p_k[/tex] and [tex]q_k[/tex] be the numbers of admissible beginnings of length [tex]k[/tex] (first digit non-zero, no two adjacent prime digits) that end with a prime digit and with a non-prime digit, respectively, and let [tex]T_k=p_k+q_k[/tex]. For the first digit (the non-prime non-zero digits are [tex]1, 4, 6, 8, 9[/tex])
[tex]p_1=4,\qquad q_1=5,\qquad T_1=9[/tex]
A prime digit may follow only a non-prime digit, and a non-prime digit may follow any digit, hence
[tex]p_{k+1}=4q_k,\qquad q_{k+1}=6T_k[/tex]
Then [tex]T_2=4\times 5+6\times 9=74[/tex], and for [tex]k\ge 2[/tex]
[tex]T_{k+1}=6T_k+4q_k=6T_k+24T_{k-1}[/tex]
Therefore
[tex]T_3=6\times 74+24\times 9=660,\qquad T_4=6\times 660+24\times 74=5736[/tex]
[tex]T_5=6\times 5736+24\times 660=50\,256,\qquad T_6=6\times 50\,256+24\times 5736=439\,200[/tex]
[tex]T_7=6\times 439\,200+24\times 50\,256=3\,841\,344[/tex]
So the required number is
[tex]9\,000\,000-3\,841\,344=5\,158\,656[/tex]