#include<stdio.h> int main() { int k,k1=1,n,a=0; scanf("%d %d",&k,&n); while(n!=0) { a+= n%2? k1:0; k1*=k; n/=2; } printf("%d",a); return 0; }
http://www.rqnoj.cn/Problem_4.html