Skip to content

3272. Find the Count of Good Integers #1550

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to count the number of n-digit integers (called good integers) that can be rearranged into a k-palindromic integer. A k-palindromic integer is a palindrome that is divisible by k. The solution involves generating all possible palindromes of length n, checking their divisibility by k, and then counting the valid permutations of their digits that do not have leading zeros.

Approach

  1. Generate Palindromes: Generate all possible palindromes of length n. For even n, generate the first half and mirror it. For odd n, generate the first half, middle digit, and mirror the first half. Special handling is required for n=1.
  2. Check Divisibility: For each generated palindrome, check if it is divi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Apr 12, 2025
Maintainer Author

Answer selected by basharul-siddike
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 hard Difficulty
2 participants