题目描述
Problem Description
In computer networks, all data is transmitted in binary form. However, when transmitting large amounts of data, using the binary form of the number directly often results in excessive bits being transmitted. For example, transmitting $1024$ requires $11$ binary digits. Xiaoke has proposed an idea for optimizing data transmission and plans to test this concept.
The idea is to form an increasing sequence $\{a(k)n\}$ consisting of all powers of a positive integer and the sums of any number of distinct powers of $k$. For instance, when $k=3$, the first $7$ terms of $\{a(k)n\}$ are $1(=3^0)$, $3(=3^1)$, $4(=3^0+3^1)$, $9(=3^2)$, $10(=3^0+3^2)$, $12(=3^1+3^2)$, and $13(=3^0+3^1+3^2)$.
If the number $d$ is the $p$-th term in the sequence $\{a(k)n\}$, then $d$ can be represented by transmitting the numbers $k$ and $p$. Since $k$ and $p$ are relatively small and can express large numbers, theoretically, this can reduce the number of bits transmitted over the network.
Xiaoke now asks you to write a program that calculates the number $d$ represented by the received numbers $k$ and $p$.
Input Format
The file contains two positive integers $k$ and $p$ on a single line, where $1 < k \le 1024$ and $1 \le p \le 1024$.
Output Format
Output the solution on a single line (the number of digits in the solution does not exceed $50$).
Sample Input and Output
Sample Input #1
3 2
Sample Output #1
3
Sample Input #2
3 7
Sample Output #2
13
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分