#3272

Find the Count of Good Integers

hard · 69.5% accepted · 464 likes · top 77%

hash table · math · combinatorics · enumeration

⊣ practice⊣ open on leetcode ↗

Description

You are given two positive integers n and k.

An integer x is called k-palindromic if:

- x is a palindrome.

- x is divisible by k.

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 that any integer must not have leading zeros, neither before nor after rearrangement. For example, 1010 cannot be rearranged to form 101.

Solution