-
Notifications
You must be signed in to change notification settings - Fork 0
/
PE_381.tex
115 lines (77 loc) · 2.75 KB
/
PE_381.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
\addcontentsline{toc}{chapter}{381 - (prime-k) factorial}
\chapter*{381 - (prime-k) factorial}
\index{Extended Euclidean} \index{inverse multiplicative} \index{modular arithmetic} \index{Wilson's theorem}
For a prime $p$ let $S(p) = \left ( \sum_{k=1}^5(p-k)! \right ) \bmod{p}$.\\
For example, if $p=7$,
\begin{align*}
\sum_{k=1}^5(p-k)! &= (7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)!\\
&= 6! + 5! + 4! + 3! + 2!\\
&= 720+120+24+6+2\\
&= 872.
\end{align*}
As $872 \bmod{7}$ = 4, $S(7) = 4$.\\
It can be verified that $\sum_{p=5}^{99} S(p) = 480$.\\
Find $\sum_{p=5}^{10^8} S(p)$.
\section*{Solution}
By doing simple math and using modular arithmetic we get the $S(p)$ is defined by
\begin{align*}
S(p) &= \left ( (p-5)! \bmod p \right ) \times 9 \\
&= \left ( \left ( \frac{(p-1)!}{(p-1)(p-2)(p-3)(p-4)} \right ) \bmod p \right ) \times 9
\end{align*}
According to Wilson's Theorem \cite{wilson_theorem},
$$
(n-1)! \bmod n = -1 \bmod n
$$
When $n$ is prime.\\
Then, we only need to get rid of the denominator by using modular arithmetic. More precisely by using the inverse multiplicative. Suppose we have the following operation
$$
\frac{a}{b} \bmod m
$$
we can rewrite it as
$$
\left ( a \bmod m \right ) \left ( \frac{1}{b} \bmod m \right )
$$
The inverse multiplicative of $b$ is a number $k$, such that $(bk) \bmod m = 1$. Getting back to our problem, we are looking for an integer $k$ such that
$$
k(p-1)(p-2)(p-3)(p-4) \bmod p = 1
$$
Using modular arithmetic we have that
\begin{align*}
(k(-1)(-2)(-3)(-4)) \bmod p &= 1 \\
24k \bmod p &= 1
\end{align*}
Then
\begin{align*}
S(p) &= \left ( \frac{(p-1)!}{24} \bmod{p} \right ) \times 9 \\
&= \left ( (p-1)! \frac{3}{8} \right ) \bmod p \\
&= (-1 \bmod p) (3k \bmod p) \\
&= (-3 \bmod p) (k \bmod p)\\
&= (p-3)(k \bmod p)
\end{align*}
where $8k \bmod p = 1$\\
The value of $k$ can be found using the \textit{Extended Euclidean Algorithm}, which finds the inverse multiplicative of a number $a \bmod n$, only when $a$ and $m$ are coprimes. Since for our problem $m$ is prime, we can use it.\\
The \textit{Extended Euclidean Algorithm} find the values of $x$ and $y$ that solve the following equation:
$$
ax + by = 1
$$
Using $a=8$ and $b=p$ we have
$$
8x + py = 1
$$
Obtaining the modulus in both sides of the equation we get
\begin{align*}
(8x + py) \bmod p &= 1 \\
8x \bmod p &= 1
\end{align*}
which is what we are looking for. So basically we must calculate the value of $x$ using the \textit{Extended Euclidean Algorithm} and add the value of $p$ to avoid negative values. Then
$$
(x,y) = \mbox{ExtendedEuclidean}(8,p)
$$
and
$$
k = \left (x + p \right ) \bmod p
$$
Finally the value of $S(p)$ is given by
$$
S(p) = \left ( (p-3) \times k \right ) \bmod p
$$