// CORRCHK Solution. Written by Sergey Kulik #include #include using namespace std; int Tn, i, max_digit, base, fl, ret; string s, a, b, c; int getd (char c) { // gets the number that corresponds to the character if (c <= '9') return c - '0'; else return c - 'a' + 10; } long long tran (string a, long long base) { // translates the string a to the numberal system base long long ret = 0; for(int i = 0; i < a.length(); i++) ret = ret * base + getd(a[i]); return ret; } int main (int argc, char * const argv[]) { cin >> Tn; while (Tn--) { cin >> s; a = b = c = ""; for(i = 0; i < s.length(); i++) if (s[i] != '+') a += s[i]; else break; // finding a ++i; for(; i < s.length(); i++) if (s[i] != '=') b += s[i]; else break; // finding b ++i; for(; i < s.length(); i++) c += s[i]; // finding c max_digit = fl = 0; for(i = 0; i < s.length(); i++) if (s[i] != '+' && s[i] != '=') max_digit = max(max_digit, getd(s[i]) + 1); // finding the smallest possible numeral system for(base = max_digit; base <= 16; base++) if (tran(a, base) + tran(b, base) == tran(c, base)) fl = 1; // trying to find a suitable numeral system ret += fl; } cout << ret << endl; return 0; }