Find the Count of Good Integers - Problem
You are given two positive integers n and k.
An integer x is called k-palindromic if:
xis a palindromexis divisible byk
An integer is called good if its digits can be rearranged to form a k-palindromic integer.
For example, for k = 2, 2020 can be rearranged to form the k-palindromic integer 2002, whereas 1010 cannot be rearranged to form a k-palindromic integer.
Return the count of good integers containing n digits.
Note: Any integer must not have leading zeros, neither before nor after rearrangement. For example, 1010 cannot be rearranged to form 101.
Input & Output
Example 1 — Basic Case
$
Input:
n = 3, k = 5
›
Output:
27
💡 Note:
For 3-digit numbers, we need palindromes like ABA where A∈{1-9}, B∈{0-9}. Count arrangements that form palindromes divisible by 5.
Example 2 — Single Digit
$
Input:
n = 1, k = 4
›
Output:
2
💡 Note:
Single digits divisible by 4: only 4 and 8. So count is 2.
Example 3 — Even Length
$
Input:
n = 2, k = 6
›
Output:
4
💡 Note:
2-digit palindromes divisible by 6: must be divisible by both 2 and 3. Examples: 66 (rearrangement of 66).
Constraints
- 1 ≤ n ≤ 15
- 1 ≤ k ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
n=3 digits, k=5 (divisibility requirement)
2
Process
Find digit arrangements that form palindromes divisible by 5
3
Output
Count of good integers
Key Takeaway
🎯 Key Insight: Generate palindrome digit patterns and use combinatorics to count valid arrangements without explicit enumeration
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code