Find the sum of the first positive integers that are palindromic in base 10 and also in base .
Problem
A positive integer is called -mirror if it is a palindrome in both base 10 and base .
Given two integers and , return the sum of the first positive integers that are -mirror numbers.
A number is a palindrome if it reads the same forward and backward in its base representation.
Clarification
You should consider positive integers only, and the numbers should be counted in increasing order.
Goal
Generate the first numbers that satisfy both palindrome conditions, then return their sum.
Input Format
- One line containing two integers and .
- is the count of -mirror numbers to find.
- is the base used for the second palindrome check.
Output Format
- Return a single integer: the sum of the first -mirror numbers.
Constraints
- The numbers searched are positive integers.
- The answer fits in a 64-bit signed integer for the intended test data.
Example 1
Input
n = 5, k = 2
Output
25
Explanation
The first five positive integers that are palindromic in both base 10 and base 2 are 1, 3, 5, 7, and 9. Their sum is 25.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.