#P3923. 大学数学题

    ID: 2862 远端评测题 1000~3000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创提交答案Special Judge素数判断,质数,筛法进制期望

大学数学题

Description

Rumia: The Great Fairy wants to construct a finite field of order n n , where the elements are represented by the integers 0n1 0 \sim n - 1 .

A finite field must satisfy the following conditions:

  1. There exists an additive identity o o , such that for any element a a , o+a=a+o=a o + a = a + o = a .
  2. For any element a a , there exists an additive inverse a1 a^{-1} , such that a+a1=a1+a=o a + a^{-1} = a^{-1} + a = o .
  3. There exists a multiplicative identity i i different from the additive identity o o , such that for any element a a , i×a=a×i=a i \times a = a \times i = a .
  4. For any element a a that is not the additive identity, there exists a multiplicative inverse a1 a^{-1} , such that a×a1=a1×a=i a \times a^{-1} = a^{-1} \times a = i .
  5. For any elements x x , y y , addition is commutative, i.e., x+y=y+x x + y = y + x .
  6. For any elements x x , y y , multiplication is commutative, i.e., x×y=y×x x \times y = y \times x .
  7. For any elements x x , y y , z z , addition is associative, i.e., (x+y)+z=x+(y+z) ( x + y ) + z = x + ( y + z ) .
  8. For any elements x x , y y , z z , multiplication is associative, i.e., $( x \times y ) \times z = x \times ( y \times z )$.
  9. For any elements x x , y y , z z , multiplication distributes over addition, i.e., (x+y)×z=x×z+y×z ( x + y ) \times z = x \times z + y \times z .

The Great Fairy certainly knows how to do it, but she wants to test you.

In the output, the additive identity o o is 0 0 , and the multiplicative identity i i is 1 1 .

Description

Input Format

A positive integer n n (2n350 2 \leq n \leq 350 ).

Output Format

On the first line, output an integer k k . If a finite field of order n n exists, then k=0 k = 0 ; otherwise k=1 k = -1 .

If k=0 k = 0 , then:

  1. Output an n n -by-n n addition table of the finite field in the next n n lines. The number in row i+1 i + 1 , column j+1 j + 1 represents the result of i+j i + j in the field.
  2. Output an n n -by-n n multiplication table of the finite field in the following n n lines. The number in row i+1 i + 1 , column j+1 j + 1 represents the result of i×j i \times j in the field.

In total, output n×2+1 n \times 2 + 1 lines.

upd1: The SPJ is very strict. Do not output extra spaces at the ends of lines (the trailing newline at the end of the file will still be ignored).

upd2: The official correct-answer file is large, so Luogu may keep judging... If this happens, please submit the source code directly.

2

0
0 1
1 0
0 0
0 1

Hint

Test point Range of n n Special property
1 n=3 n = 3 n n is prime
2 n=4 n = 4 n n is an integer power of 2 2
3 n=6 n = 6 None
4 n=8 n = 8 n n is an integer power of 2 2
5 n=9 n = 9 None
6 n=19 n = 19 n n is prime
7 n=89 n = 89
8 n=181 n = 181
9 n=233 n = 233
10 n=25 n = 25 n n is a square of a prime
11 n=121 n = 121
12 n=169 n = 169
13 n=27 n = 27 None
14 n=143 n = 143
15 n=128 n = 128 n n is an integer power of 2 2
16 n=81 n = 81 None
17 n=125 n = 125
18 n=243 n = 243
19 n=256 n = 256 n n is an integer power of 2 2
20 n=343 n = 343 None

Translated by ChatGPT 5