Alien Communication Masterclass
Time limit3sMemory limit256 MB
Given true bases and false bases, output a fixed-form product-of-factors equation that holds only for the true bases in that numeral system.
- Level
Easy3 of 10
- Topics
- Math, Implementation, String
- Solved
- No attempts yet
Problem
Andrea is a famous science-fiction writer who runs masterclasses for her readers. Her most popular course teaches how to behave when you encounter alien life forms, or at least alien artifacts.
One lecture is about extracting useful information from aliens' writings. Andrea explains that, from an alien mathematical formula, one can deduce the base of the numeral system the aliens use, which in turn hints at their biology. (For example, we use base 10 because we have ten fingers on our hands.)
Assume, for simplicity, that aliens use the same digits we do, and that they write addition, subtraction, multiplication, parentheses, and equality exactly as we do.
For her lecture Andrea wants a mathematical equality that is true in the numeral systems with bases but false in the numeral systems with bases . To make the answer unique, build the equality in the fixed canonical form described in the Output section.
Input
The first line contains two integers and ().
The second line contains the true bases .
The third line contains the false bases .
All of are distinct and lie between and , inclusive.
Output
In base the string 10 has the value , so it denotes the numeral-system base itself. Therefore the factor evaluates to in base , and the product of these factors over all true bases equals . This product is exactly when the base is one of and nonzero for every other base; setting it equal to gives an equality that holds precisely in the true bases (and, because the true and false bases are distinct, in none of the false bases).
Output exactly this canonical equality, constructed as follows:
- Sort the true bases in increasing order .
- For each write the factor
(10-1-...-1)containing exactly subtracted1s (for example gives(10-1-1)). - Join the factors with
*and append=0.
Print the whole equality on a single line with no spaces. Use only the characters 0, 1, (, ), -, *, and =.