Finding the Two Bases
Time limit1sMemory limit256 MB
Find the two bases between 10 and 15000 where the two given 3-digit sequences represent the same number.
- Level
Medium5 of 10
- Topics
- Math, Brute force
- Solved
- No attempts yet
Problem
Bessie the cow is taking computing classes at her local college, and she recently learned how to write numbers in different bases.
A number written in base has digit places representing , , , , and so on from right to left. In the familiar base system the places represent , , , , and so on. The digit sequence read in base means . The same digit sequence read in base means , which is in base . When the base grows, the number represented by a fixed digit sequence grows too. For example, in base is larger than in base .
In base each digit ranges from to , so base digits run from to and base digits run from to . Bases larger than are allowed. Computer scientists often use base , where the letters A to F stand for the digit values to . In base the sequence BEEF means , which is in base .
Bases much larger than interest Bessie. She took a number and wrote it down in two different bases and , both between and . In both cases she got a sequence of digits, and every one of those digits was between and . Bessie has since forgotten , , and . Given only the two 3-digit sequences she wrote down, find the two bases and she used.
Because and can be large, a program that tries every possible pair checks nearly possibilities and does not finish within the time limit.
Input
The first line contains an integer . Each of the next lines holds one test case, made of two 3-digit numbers. The first is a number written in base , and the second is the same written in base . , , and may differ from test case to test case.
Output
Print lines, one per test case. On each line print and for that test case, separated by a single space. Each test case is guaranteed to have exactly one answer.
Hint
The number written in base is , and written in base it is .