Math Fundamentals18 sections · 814 units
Open in Course

Problem - Count Good Numbers

LeetCode 1922

A digit is even if it's 0, 2, 4, 6, or 8. A digit is prime if it's 2, 3, 5, or 7. A number is good if digits at even indices (0, 2, 4, ...) are even digits, and digits at odd indices (1, 3, 5, ...) are prime digits.

Given nn, count how many nn-digit good numbers exist. Return the answer modulo 109+710^9 + 7.

For n=1n = 1, you have 5 choices (0, 2, 4, 6, 8). For n=2n = 2, the first digit has 5 choices, the second has 4 (2, 3, 5, 7). Total: 5×4=205 \times 4 = 20.