AT_abc414_c [ABC414C] Palindromic in Both Bases
Description
The decimal representation of $ 414 $ is `414`, which is a palindrome. Also, the octal representation of $ 414 $ is `636`, which is also a palindrome. Based on this, solve the following problem.
You are given positive integers $ A $ and $ N $ . Find the sum of all integers between $ 1 $ and $ N $ , inclusive, whose decimal representation and base- $ A $ representation are both palindromes.
Under the constraints of this problem, it can be proved that the answer is less than $ 2^{63} $ .
Input Format
The input is given from Standard Input in the following format:
> $ A $ $ N $
Output Format
Output the answer in one line.
Explanation/Hint
### Sample Explanation 1
The integers satisfying the condition are $ 1,2,3,4,5,6,7,9,121,292,333,373,414,585 $ ( $ 14 $ integers), and their sum is $ 2155 $ .
### Constraints
- $ 2 \leq A \leq 9 $
- $ 1 \leq N \le 10^{12} $
- All input values are integers.