#include #include int base; int hex2dec(char c) { if (c== '*') return 0; if (c <= '9') return c-'0'; return c-'A'+10; } char dec2hex(int c) { if (c > 9) return c-10+'A'; return c+'0'; } void secti(char *s, char *t) { char buf[10240],buf2[10240], res[10240]; int i, j, k; int prenos; for (i=0; i<1005; i++) buf[i] = buf2[i] = '*'; buf[1005] = buf2[1005] = 0; strcat(buf, s); strcat(buf2, t); i = strlen(buf)-1; j = strlen(buf2)-1; k = 1200; res[k] = 0; prenos = 0; while(buf[i] != '*' || buf2[j] != '*') { int l; l = hex2dec(buf[i]) + hex2dec(buf2[j]) + prenos; prenos = 0; if (l >= base) { prenos = 1; l -= base; } res[--k] = dec2hex(l); i--; j--; } if (prenos) res[--k] = '1'; printf("%s", res+k); if (!res[k]) putchar('0'); } int main (int argc, char **argv) { char t [65536]; while (1) { char *s; int i; scanf("%d\n", &base); if (!base) break; gets(t); s = strchr(t, ' '); *s = 0; s++; printf("%s + %s = ", t, s); if (base == 1) { int i1, i2; i1 = s[0]=='0' ? 0 : strlen(s); i2 = t[0]=='0' ? 0 : strlen(t); if (i1+i2 == 0) putchar('0'); else { for (i=0; i