CCC '06 S4 - Groups


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem types
Allowed languages
C++, Python

\displaystyle \begin{array}{c|cccccc}
\times & i & a & b & c & d & e \\\hline
i & i & a & b & c & d & e \\
a & a & i & d & e & b & c \\
b & b & e & i & d & c & a \\
c & c & d & e & i & a & b \\
d & d & c & a & b & e & i \\
e & e & b & c & a & i & d \end{array} \[\displaystyle \begin{array}{c|cccccc} \times & i & a & b & c & d & e \\\hline i & i & a & b & c & d & e \\ a & a & i & d & e & b & c \\ b & b & e & i & d & c & a \\ c & c & d & e & i & a & b \\ d & d & c & a & b & e & i \\ e & e & b & c & a & i & d \end{array}\]

Your task is to write a program which will read a sequence of multiplication tables and determine whether each structure defined is a group.

Input Specification

The input will consist of a number of test cases. Each test case begins with an integer \(n\) \((0 \le n \le 100)\) . If the test case begins with \(n = 0\) , the program terminates. To simplify the input, we will use the integers \(1, \dots, n\) to represent elements of the candidate group structure; the identity could be any of these (i.e., it is not necessarily the element \(1\) ). Following the number \(n\) in each test case are \(n\) lines of input, each containing integers in the range \([1, \dots, n]\) . The \(q^{th}\) integer on the \(p^{th}\) line of this sequence is the value \(p \times q\) .

Output Specification

If the object is a group, output yes (on its own line), otherwise output no (on its own line). You should not output anything for the test case where \(n = 0\) .

Sample Input

2
1 2
2 1
6
1 2 3 4 5 6
2 1 5 6 3 4
3 6 1 5 4 2
4 5 6 1 2 3
5 4 2 3 6 1
6 3 4 2 1 5
7
1 2 3 4 5 6 7
2 1 1 1 1 1 1
3 1 1 1 1 1 1
4 1 1 1 1 1 1
5 1 1 1 1 1 1
6 1 1 1 1 1 1
7 1 1 1 1 1 1
3
1 2 3
3 1 2
3 1 2
0

Sample Output

yes
yes
no
no

Explanation

The first two collections of elements are in fact groups (that is, all properties are satisfied). For the third candidate, it is not a group, since \(3 \times (2 \times 2) = 3 \times 1 = 3\) but \((3 \times 2) \times 2 = 1 \times 2 = 2\) . In the last candidate, there is no identity, since \(1\) is not the identity, since \(2 \times 1 = 3\) (not \(2\) ), and \(2\) is not the identity, since \(2 \times 1 = 3\) (not \(1\) ) and \(3\) is not the identity, since \(1 \times 3 = 3\) (not \(1\) ).


Comments

There are no comments at the moment.