输入若干行,每行一个十进制数x,以及一个目标进制数c
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i=(a); i<=(b); i++)
#define lop(i, a, b) for(int i=(a); i<(b); i++)
#define el "\n"
typedef long long LL;
const int N = 100010;
const double PI = acos(-1);
void change(int x, int c)
{
map<int, char> m;
stack<char> sta;
if(x < 0) cout << "-";
x = abs(x);
if(c < 10)
lop(i, 0, c) m[i] = '0'+i;
else
{
lop(i, 0, 10) m[i] = '0'+i;
lop(i, 10, c) m[i] = 'a'+i-10;
}
while(x)
{
int temp = x % c;
sta.push(m[temp]);
x /= c;
}
while(sta.size())
{
cout << sta.top();
sta.pop();
}
}
int main ()
{
cin.tie(0);
cout.tie(0);
int x, c;
while(cin >> x >> c)
{
change(x, c);
cout << el;
}
return 0;
}