1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 const int maxn = 10005; 5 char biao[] = "0123456789ABCDEF"; 6 int main(){ 7 int a, b; 8 char s[maxn]; 9 int len; 10 while (cin >> a >> b){ 11 int ans = 0; 12 len = 0; 13 int t; 14 while (a){ 15 int t; 16 t = a % b; 17 ans += t; 18 a /= b; 19 } 20 while (ans){ 21 int t; 22 t = ans % b; 23 ans /= b; 24 s[len++] = biao[t]; 25 } 26 for (int i = len - 1; i >= 0; i--){ 27 cout << s[i]; 28 } 29 cout << endl; 30 } 31 32 //system("pause"); 33 return 0; 34 }