#include <iostream> #include<algorithm> #include<string.h> using namespace std; const int N = 1010; char a[N]; char b[N]; int m; int n; int num =0; void transf(char a[],char b[],int m,int n){ int temp; int sum = 0; char c; int len=strlen(a); for(int i=0;i<len;i++){ if(a[i]>='0'&&a[i]<='9') temp = a[i]-'0'; else temp = a[i]-'A'+10; sum = sum*m+temp; } cout<<sum<<endl; int i=0; while(1){ temp = sum %n; if(temp<=9) b[i] = temp+'0'; else b[i] = temp+'A'-10; sum/=n; if(sum ==0) break; i++; } } int main() { gets(a); cin>>m; cin>>n; transf(a,b,m,n); int len = strlen(b); for(int i=len-1;i>=0;i--) cout<<b[i]; return 0; }