#include <iostream>
#include <cmath>
#include <stack>
using namespace std;
int main()
{
long long N,R;
while(cin>>N>>R)
{
stack <char> s;
if(N<0)
cout<<"-";
long long tmp1=abs(N);
while(tmp1!=0)
{
int tmp2=tmp1%R;
if(tmp2>9)
s.push(char(tmp2-10+'A'));
else
s.push(char(tmp2+'0'));
tmp1/=R;
}
while(!s.empty())
{
cout<<s.top();
s.pop();
}
cout<<endl;
}
}
tips:一次AC了 !好开心!!