Homework
Time limit2sMemory limit256 MB
For each triple of decimal strings x, y, z, decide whether infinitely many bases k make x times y equal z when read in base k.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Implementation, Brute force
- Solved
- No attempts yet
Problem
In informatics class today, Petya learned about numeral systems with different bases. A base- numeral system uses digits with weights from 0 to ; the first 10 digits are written with ordinary digits, and beyond that Latin letters and other symbols are also used.
Now Petya is trying to solve the following homework. Numbers , , and written with decimal digits are given. Find every base such that all digits used in the numbers exist in this numeral system and, when , , and are treated as numbers written in base , the product of and equals .
Petya started solving this problem and discovered that under some conditions infinitely many different values of work. He decided to first determine whether this case occurs. Help him find out.
Input
The first line contains the number , the number of tests in the input ().
Then follow test descriptions. Each test is described by three lines containing the numbers , , and , respectively. Each of these numbers is positive, consists only of decimal digits, and has no leading zeros. The length of each of and does not exceed 100, and the length of does not exceed 200.
Output
For each test, output its answer on a separate line: Infinity if there are infinitely many values of such that treating the input numbers as written in base makes the product of and equal , or Finite if there are finitely many such .