java 代码
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int k = input.nextInt();
int N = input.nextInt();
int c = 1;
int res = 0;
while(N > 0){
if((N & 1) == 1){
res += c;
}
c *= k;
N = N >> 1;
}
System.out.println(res);
}
}