#P1062. [NOIP 2006 普及组] 数列

[NOIP 2006 普及组] 数列

Description

Given a positive integer kk (3k153 \leq k \leq 15), form an increasing sequence consisting of all powers of kk and all sums of finitely many distinct powers of kk. For example, when k=3k = 3, the sequence is:

1,3,4,9,10,12,13,1, 3, 4, 9, 10, 12, 13, \ldots

(This sequence is in fact: 30,31,30+31,32,30+32,31+32,30+31+32,3^0,3^1,3^0+3^1,3^2,3^0+3^2,3^1+3^2,3^0+3^1+3^2,….)

Please compute the value of the NN-th term of this sequence and output it in base 1010 (decimal).

For example, for k=3k = 3 and N=100N = 100, the correct answer is 981981.

Input Format

Two positive integers kk and NN separated by a space (3k153 \leq k \leq 15, 10N100010 \leq N \leq 1000).

Output Format

A single positive integer. Do not print any spaces or other symbols before the integer.

3 100
981

Hint

NOIP 2006 Junior Problem 4.

Translated by ChatGPT 5