Skip to content

1922. Count Good Numbers #1554

Answered by mah-shamim
mah-shamim asked this question in Q&A
Apr 13, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to count the number of good digit strings of length n where a digit string is considered good if the digits at even indices are even and the digits at odd indices are prime numbers (2, 3, 5, or 7). The result should be returned modulo 109 + 7.

Approach

  1. Identify Positions: For a given length n, determine the number of even and odd indices. Even indices are 0, 2, 4, ..., and odd indices are 1, 3, 5, ... . The count of even indices is (n + 1) // 2 and the count of odd indices is n // 2.
  2. Calculate Possibilities:
    • Each even position can be filled with 5 possible even digits (0, 2, 4, 6, 8).
    • Each odd position can be filled with 4 possible prime digits (2, 3, 5, 7).
  3. Modular Exponentia…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Apr 13, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Apr 13, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants