Sum of k-Mirror Numbers

A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.

Given the base k and the number n, return the sum of the n smallest k-mirror numbers.

Example 1
Inputk = 2, n = 5
Output25
The 5 smallest 2-mirror numbers are 1, 3, 5, 7, and 9, whose sum is 25.
Example 2
Inputk = 3, n = 7
Output499
The 7 smallest 3-mirror numbers are 1, 2, 4, 8, 121, 151, and 212, whose sum is 499.

Constraints

  • 2 <= k <= 9
  • 1 <= n <= 30

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate