Dihedral Group Product
Time limit5sMemory limit128 MB
Multiply two given elements of D_{m,n} with the relation ba = a^{m-1}b and print each product with exponents reduced modulo m and n.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
A dihedral group is a set with a multiplication defined on it. Every element of is built from two elements and . The multiplication sign is almost never written out: the factors are written next to each other or collapsed into exponents. So is written or , and is written or .
A dihedral group takes two parameters and with and , and is written . Three relations hold in .
therefore has exactly elements.
For and , consists of these 14 elements.
The multiplication is not commutative, so . In the third relation reads . Powers of a single letter combine as and , but once the two letters mix you cannot simply add the exponents.
Here is the correct way to multiply by in . First rewrite the in the middle as .
Since , the first two factors collapse into .
Clean up the remaining product the same way.
So .
Given , , and two elements and of , write a program that computes their product.
Input
The input consists of several problem sets.
The first line of each problem set contains a problem ID and , , , separated by spaces. The problem ID is a string of uppercase letters and digits with no spaces, and are integers between and , and is the number of multiplication questions in that set. Each of the next lines holds one question, two elements of separated by a space. An element is written as the letter a, an exponent, the letter b, and an exponent run together, like a3b1, and the exponents carry no leading zeros.
One problem set is followed immediately by the next. A line whose problem ID is ZZ marks the end of the input, and the rest of that line is ignored.
Output
For each multiplication question, print one line in this format.
ProblemID id: ajbk * apbq = arbs
id is the problem ID of that set, ajbk and apbq are the two input elements copied exactly as they were given, and arbs is their product. Write the result exponents so that and , and put a single space after the colon and on both sides of * and =.