<PREV Problem:
NEXT>
Solved by 87 users: ...
UserDateAttemptTimeCMSC
daniel.ugra13 jan 2007Ruby1000.26272 
mikelan02 mar 2012C500.90336 
toshiba204 jan 2007C++800.26394 
NIGHTFIT31 oct 2011C++1700.22432 
NIGHTFIT31 oct 2011C++1400.21433 
wanghanga_104 dec 2006C++200.64489 
fzszjs1z04 dec 2006C++500.64489 
davidsun29 may 2008C++1201.53501 
davidsun29 may 2008C++1001.51507 
toshiba204 jan 2007FPC700.22510 
katuxa19 feb 2011C++2801.01518 
vislipuzly18 feb 2011C++301.05518 
checkil19 feb 2011C++301.06518 
NIGHTFIT31 oct 2011C++1300.20522 
Languages
C++
56
Kylix
13
FPC
9
Java
7
C
2
Ruby
1
Python
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Unique radix

Time limit = 2 second(s)

Memory limit = 33000 Kb

You are given set of equation of the form "X*Y=Z" or "X+Y=Z".

You have to find radix (base of number representation) for which these equations are true.

Input First line of input contains number of equations N, 0 < N ≤ 1000. Each of next N lines contains equation description of form

X*Y=Z
or
X+Y=Z
where X, Y, and Z are positive integer number representations, namely Z, Y and Z are words from B^*, B={0,1,..,9,a,..,z}. Their lengths are less than 11. Letters 'a', 'b', ..,'z' correspond to "digits" 10, 11, .. 35.

If radix can be determined uniquely, then numbers X, Y, Z do not exceed 264 — 1.

Output Output proper radix if it is unique. Output "0" if the radix does not exist. Output "-1" if it exists but not unique.

Input#1
3 
2*2=4 
25*25=625 
10+10=20

Output#1
10

Input#2
1 
2*2=5

Output#2
0

Input#3
1 
2*2=4

Output#3
-1

Author:
First Moscow Individual Programming Championship, 17 October 2004, MIPT

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 200ms

SW soft NIX
ID = 3.230.148.211