Let $p$ be a prime number greater than 2. Patricia wants to assign 7 not necessarily distinct numbers from $\{1,2, \ldots, p\}$ to the black dots in the figure below, in such a way that the product of the three numbers on a line or circle always has the same remainder when divided by $p$.
![](https://cdn.mathpix.com/cropped/2024_12_06_2dfd52eb2f353e556748g-3.jpg?height=386&width=438&top_left_y=653&top_left_x=822)
(a) Suppose Patricia uses the number $p$ at least once. How many times does she minimally need the number $p$ in total?
(b) Suppose Patricia does not use the number $p$. In how many ways can she then assign the numbers? (Two ways are different if different numbers are assigned to at least one black dot. The figure is not rotated or reflected.)
(a) By 'lines' we mean in the following part of this section the six lines and the circle. Whenever the number $p$ is used somewhere, there is a 'line' with a product divisible by $p$, so with a remainder of 0 after division by $p$. Then all 'lines' must give a remainder of 0, so all 'lines' must contain $p$ at least once. This can be achieved by assigning the number $p$ to the bottom three dots. Suppose it can also be done with at most two $p$s. Each dot lies on exactly three 'lines', so then there are at most six 'lines' on which a number $p$ lies. However, there are seven 'lines', so this is not possible. We conclude that it needs $p$ at least three times in total.
(b) Let the bottom three numbers from left to right be $a, b$, and $c$. Let the number in the middle of the left side of the triangle be $d$. We can now calculate all numbers modulo $p$; note that all numbers are invertible modulo $p$ because $p$ itself does not participate and $p$ is prime. The bottom line has the product $a b c$. The left side of the triangle also does, so the number at the very top is congruent modulo $p$ to $a b c(a d)^{-1}=b c d^{-1}$. If we look at the line from the bottom right to the middle of the left side, we see that the middle number must be congruent to $a b c(c d)^{-1}=a b d^{-1}$. By looking at the circle, we find that the number on the right in the middle is $a b c(b d)^{-1} = a c d^{-1}$.

On the right side, we now get the equation $b c d^{-1} \cdot a c d^{-1} \cdot c \equiv a b c \bmod p$, so $c^{2} \equiv d^{2} \bmod p$. Similarly, we find on the vertical line $b^{2} \equiv d^{2}$ and on the line from the bottom left to the middle right $a^{2} \equiv d^{2} \bmod p$. We conclude that the numbers $a, b, c$, and $d$ must all have the same square. From $x^{2} \equiv y^{2}$ follows $(x-y)(x+y) \equiv 0 \bmod p$, so $p \mid x-y$ or $p \mid x+y$, because $p$ is prime. Thus, $x \equiv y$ or $x \equiv -y$. There are two options, because if $y \equiv -y$, then $2 y \equiv 0$, so $p \mid 2 y$, so $p \mid y$ due to $p>2$; contradiction. Therefore, the numbers $b, c$, and $d$ must all be congruent to $a$ or $-a$. If this condition is met, then $a^{2} \equiv b^{2} \equiv c^{2} \equiv d^{2}$ and then it follows from the above that on all six lines and on the circle the product is congruent to $a b c$.
There are $p-1$ possibilities for the number $a$ and then 2 possibilities for each of the numbers $b, c$, and $d$. So in total, there are $8(p-1)$ ways to assign the numbers.