#include #define BASE 7 unsigned long int BASEto10(unsigned long int); unsigned long int DECtoBASE(unsigned long int); long long int BASEaddition(unsigned long int, unsigned long int); long long int BASEsubtraction(unsigned long int, unsigned long int); long long int BASEmultiplication(unsigned long int, unsigned long int); int main(void) { unsigned long int a,b,c; scanf("%ld", &a); scanf("%ld", &b); if (BASEsubtraction(a, b) >= 0) { c = BASEsubtraction(a, b); if (BASEmultiplication(a, c) >= 0) { c = BASEmultiplication(a, c); if (BASEaddition(c, a) >= 0) { c = BASEaddition(c, a); printf("%d\n", c); } else printf("!1\n"); } else printf("!3\n"); } else printf("!2\n"); return 0; } unsigned long int BASEto10(unsigned long int a) { if (a == 0) return 0; int k=1; long int a10=0; while (a) { a10 += k*(a%10); k *= BASE; a /= 10; } return a10; } unsigned long int DECtoBASE(unsigned long int a) { if (a == 0) return 0; return (a % BASE) + 10 * DECtoBASE(a / BASE); } long long int BASEaddition(unsigned long int a, unsigned long int b) { long long int c = BASEto10(a) + BASEto10(b); if ((DECtoBASE(c) < 4266666666) && (DECtoBASE(c) >= 0)) return DECtoBASE(c); return -1; } long long int BASEsubtraction(unsigned long int a, unsigned long int b) { long long int c = BASEto10(a) - BASEto10(b); if ((DECtoBASE(c) < 4266666666) && (DECtoBASE(c) >= 0)) return DECtoBASE(c); return -1; } long long int BASEmultiplication(unsigned long int a, unsigned long int b) { long long int c = BASEto10(a) * BASEto10(b); if ((DECtoBASE(c) < 4266666666) && (DECtoBASE(c) >= 0)) return DECtoBASE(c); return -1; }