#P2558. [AHOI2002] 网络传输

    ID: 1576 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp搜索2002各省省选安徽

[AHOI2002] 网络传输

Description

In computer networks, all data are transmitted in binary form. However, when transmitting large data, directly sending its binary representation often requires too many bits. For example, transmitting 10241024 needs an 1111-bit binary number. Therefore, Xiao Keke proposed an idea for optimizing data transmission and plans to test it.

The idea is: arrange in increasing order the sequence {a(k)n}\{a(k)_n\} consisting of all positive integer powers of kk, as well as sums of any number of pairwise distinct powers of kk. For example, when k=3k = 3, the first 77 terms of {a(k)n}\{a(k)_n\} are 1(=30)1(=3^0), 3(=31)3(=3^1), 4(=30+31)4(=3^0+3^1), 9(=32)9(=3^2), 10(=30+32)10(=3^0+3^2), 12(=31+32)12(=3^1+3^2), 13(=30+31+32)13(=3^0+3^1+3^2).

If a number dd is the pp-th term of the sequence {a(k)n}\{a(k)_n\}, then one can represent dd by transmitting the two numbers kk and pp. Since the relatively small numbers kk and pp can represent a very large number, this can theoretically reduce the number of bits transmitted.

Now Xiao Keke asks you to write a program to compute the number dd represented by the received kk and pp.

Input Format

A single line contains two positive integers kk and pp, with 1<k10241 < k \le 1024, 1p10241 \le p \le 1024.

Output Format

Output the answer in one line (the number of digits does not exceed 5050).

3 2
3
3 7
13

Hint

Translated by ChatGPT 5