#include using namespace std; int b; string d; main() { cin>>b>>d; if(b==2)return 1; int x; for(x=1;x0&&id>=0) { if(d[id]-48>=sub%b) { d[id]-=sub%b; } else { d[id]=d[id]-sub%b+b; sub+=b; } sub/=b; id--; } if(sub>0) { for(int i=0;i<=d.size()-x;i++)sub*=b; sub-=x*(b-1); int id=(int)d.size()-x; while(sub>0) { if(d[id]-48>=sub%b)d[id]-=sub%b; else { d[id]=d[id]-sub%b+b; sub+=b; } sub/=b; id--; } break; } } string ans=""; int carry=0; for(int i=0;i0;i--) { carry=carry*b+d[d.size()-i]-48; int t=carry/x+(i==x); int sub=carry/x*x; carry-=sub; ans+=48+t; } int now=carry; now-=x; if(carry>0) { int id=ans.size()-1; while(ans[id]-48==b-1)ans[id++]=48; ans[id]++; } else { int id=ans.size()-1; while(ans[id]-48==0)ans[id++]=48+b-1; ans[id]--; now=0; } cout<