|
| 1 | +<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> |
| 2 | + |
| 3 | +<p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> |
| 7 | + <li><code>x</code> is divisible by <code>k</code>.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>An integer is called <strong>good</strong> if its digits can be <em>rearranged</em> to form a <strong>k-palindromic</strong> integer. For example, for <code>k = 2</code>, 2020 can be rearranged to form the <em>k-palindromic</em> integer 2002, whereas 1010 cannot be rearranged to form a <em>k-palindromic</em> integer.</p> |
| 11 | + |
| 12 | +<p>Return the count of <strong>good</strong> integers containing <code>n</code> digits.</p> |
| 13 | + |
| 14 | +<p><strong>Note</strong> that <em>any</em> integer must <strong>not</strong> have leading zeros, <strong>neither</strong> before <strong>nor</strong> after rearrangement. For example, 1010 <em>cannot</em> be rearranged to form 101.</p> |
| 15 | + |
| 16 | +<p> </p> |
| 17 | +<p><strong class="example">Example 1:</strong></p> |
| 18 | + |
| 19 | +<div class="example-block"> |
| 20 | +<p><strong>Input:</strong> <span class="example-io">n = 3, k = 5</span></p> |
| 21 | + |
| 22 | +<p><strong>Output:</strong> <span class="example-io">27</span></p> |
| 23 | + |
| 24 | +<p><strong>Explanation:</strong></p> |
| 25 | + |
| 26 | +<p><em>Some</em> of the good integers are:</p> |
| 27 | + |
| 28 | +<ul> |
| 29 | + <li>551 because it can be rearranged to form 515.</li> |
| 30 | + <li>525 because it is already k-palindromic.</li> |
| 31 | +</ul> |
| 32 | +</div> |
| 33 | + |
| 34 | +<p><strong class="example">Example 2:</strong></p> |
| 35 | + |
| 36 | +<div class="example-block"> |
| 37 | +<p><strong>Input:</strong> <span class="example-io">n = 1, k = 4</span></p> |
| 38 | + |
| 39 | +<p><strong>Output:</strong> <span class="example-io">2</span></p> |
| 40 | + |
| 41 | +<p><strong>Explanation:</strong></p> |
| 42 | + |
| 43 | +<p>The two good integers are 4 and 8.</p> |
| 44 | +</div> |
| 45 | + |
| 46 | +<p><strong class="example">Example 3:</strong></p> |
| 47 | + |
| 48 | +<div class="example-block"> |
| 49 | +<p><strong>Input:</strong> <span class="example-io">n = 5, k = 6</span></p> |
| 50 | + |
| 51 | +<p><strong>Output:</strong> <span class="example-io">2468</span></p> |
| 52 | +</div> |
| 53 | + |
| 54 | +<p> </p> |
| 55 | +<p><strong>Constraints:</strong></p> |
| 56 | + |
| 57 | +<ul> |
| 58 | + <li><code>1 <= n <= 10</code></li> |
| 59 | + <li><code>1 <= k <= 9</code></li> |
| 60 | +</ul> |
0 commit comments