#include <stdio.h> #include <conio.h> #include<iostream> #include<cstring> using namespace std; long toTen(char a[],int bit) { long i,b=1,sum=0; int length=strlen(a); for (i=length-1;i>=0;i--) { if (a[i]>='A') { sum+=(a[i]-'A'+10)*b; b*=bit; } else { sum+=(a[i]-'0')*b; b*=bit; } } return sum; } void to_base_n(unsigned long n, unsigned int base) //*recursive function { int i; i = n % base; if(n >= base) { to_base_n(n/base, base); } if(i>=10) putchar('A' + i-10); else putchar('0' + i); return ; } int main(void) { char a[100];int base,last; while(1) {cin>>a>>base>>last; to_base_n( toTen(a,base),last); } return 0; }