#include<cstdio> #include<cstdlib> #include<math.h> #include"string.h" bool zero(long long *a,int len) { bool zero=true; for(int i=0;i<len;i++) if(a[i]!=0) zero=false; return zero; } int main() { //freopen("in.txt","r",stdin); int i,j,k,max,a,b,tenleft,len; char num[1000]; long long n[1000], ten[1000],x[1000]; while(scanf("%d %d",&a,&b)!=EOF) { scanf("%s",num); memset(n,0,sizeof(n)); memset(x,0,sizeof(x)); len=strlen(num); for(i=0;i<len;i++) if(num[i]<='9'&&num[i]>='0') n[i]=num[i]-'0'; else n[i]=num[i]-'A'+10; if(zero(n,len)) { printf("0\n"); continue; } j=0; while(!zero(n,len)) { tenleft=0; for(i=0;i<len;i++) { tenleft*=a; n[i]+=tenleft; tenleft=n[i]%10; n[i]/=10; } ten[j++]=tenleft; } /*for(i=0;i<j;i++) if(x[i]<=9&&x[i]>=0) printf("%d",ten[i]); else printf("%c",x[i]+'a'-10); printf("\n");*/ len=j; j=0; while(!zero(ten,len)) { tenleft=0; for(i=len-1;i>=0;i--) { tenleft*=10; ten[i]+=tenleft; tenleft=ten[i]%b; ten[i]/=b; } x[j++]=tenleft; } for(i=j-1;i>=0;i--) if(x[i]<=9&&x[i]>=0) printf("%d",x[i]); else printf("%c",x[i]+'a'-10); printf("\n"); } return 0; } /************************************************************** Problem: 1080 User: huashiyiqike Language: C++ Result: Accepted Time:280 ms Memory:1012 kb *******************