-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tex
2397 lines (1912 loc) · 127 KB
/
main.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\def\module{M3P14 Number Theory}
\def\lecturer{Prof Toby Gee}
\def\term{Autumn 2018}
\def\cover{
\begin{align*}
\pi
& = 3 + \cfrac{1}{7 + \cfrac{1}{15 + \cfrac{1}{1 + \cfrac{1}{292 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{\ddots}}}}}}}} \\
& = 0 + \cfrac{4}{1 + \cfrac{1^2}{2 + \cfrac{3^2}{2 + \cfrac{5^2}{\ddots}}}}
= 0 + \cfrac{4}{1 + \cfrac{1^2}{3 + \cfrac{2^2}{5 + \cfrac{3^2}{\ddots}}}}
= 3 + \cfrac{1^2}{6 + \cfrac{3^2}{6 + \cfrac{5^2}{6 + \cfrac{7^2}{\ddots}}}} \\
& = 2 + \cfrac{2}{\tfrac{1}{1} + \cfrac{1}{\tfrac{1}{2} + \cfrac{1}{\tfrac{1}{3} + \cfrac{1}{\ddots}}}}
= 2 + \cfrac{2}{1 + \cfrac{1 \cdot 2}{1 + \cfrac{2 \cdot 3}{1 + \cfrac{3 \cdot 4}{\ddots}}}}
= 2 + \cfrac{4}{3 + \cfrac{1 \cdot 3}{4 + \cfrac{3 \cdot 5}{4 + \cfrac{5 \cdot 7}{\ddots}}}} \\
& = 3 + \cfrac{1^3}{6 + \cfrac{1^3 + 2^3}{6 + \cfrac{1^3 + 2^3 + 3^3 + 4^3}{6 + \cfrac{1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3}{6 + \cfrac{1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3 + 7^3 + 8^3}{\ddots}}}}}
\end{align*}
}
\def\syllabus{Prime numbers and factorisation. Euclid's algorithm and consequences. Congruences. The structure of $ \unit{n} $. Primality testing and factorisation. RSA algorithm. Quadratic reciprocity. Sums of squares. Pell's equation. Continued fractions. Diophantine approximation. Primes in arithmetic progressions. Arithmetic functions. The distribution of prime numbers.}
\input{header}
\begin{document}
\input{cover}
\section{Introduction}
\lecture{1}{Friday}{05/10/18}
Roughly speaking number theory is the study of the integers. More specifically, problems in number theory often have a lot to do with primes and divisibility, congruences, and include problems about the rational numbers. For example, solving equations in integers or in the rationals, such as $ x^2 - 2y^2 = 1 $, etc. We will be looking at problems that can be tackled by elementary means, but this does not mean easy. Also the statements of problems can be elementary without the solution being elementary, such as Fermat's last theorem, or even known, such as the twin prime conjecture. Sometimes we will state interesting things, like the prime number theorem, without proving them. Typically these will be things that we could prove if the course was much longer. We will start the course with a look at prime numbers and factorisation, a review of Euclid's algorithm and consequences, congruences, the structure of $ \unit{n} $, RSA algorithm, and quadratic reciprocity. We will return to primes at the end, too. The following are typical questions here.
\begin{itemize}
\item How do you tell if a number is prime?
\item How many primes are there congruent to $ a \mod b $ for given $ a $ and $ b $?
\item How many primes are there less than $ n $?
\end{itemize}
A warning is that we will be using plenty of things from the compulsory first and second year algebra courses, about groups, rings, ideals, fields, Lagrange's theorem, the first isomorphism theorem, and so on. You may want to revise this material if you are not comfortable with it. The course is not based on any particular book, although some material, such as continued fractions, was drawn from the following.
\begin{itemize}
\item A Baker, A concise introduction to the theory of numbers, 1984
\end{itemize}
Not everything we will do is in that book, though.
\pagebreak
\section{Euclid's algorithm and unique factorisation}
\subsection{Divisibility}
\begin{definition}
If $ a, b \in \ZZ $, we say that $ a $ \textbf{divides} $ b $, and $ a \mid b $, if there exists $ c \in \ZZ $ such that $ b = ac $. If $ a $ does not divide $ b $, write $ a \nmid b $.
\end{definition}
If $ a \mid b $ and $ a \mid c $ then $ a \mid rb + sc $ for any $ r, s \in \ZZ $.
\begin{definition}
The \textbf{greatest common divisor (gcd)} or \textbf{highest common factor (hcf)} of $ a $ and $ b $ is the largest positive integer dividing $ a $ and $ b $. Write it as $ \br{a, b} $.
\end{definition}
\begin{example*}
$ \br{-10, 15} = 5 $.
\end{example*}
\begin{note*}
The ring $ \ZZ $ is a principal ideal domain (PID). If $ f_1, \dots, f_n \in R $, write $ \br{f_1, \dots, f_n} $ for the ideal generated by the $ f_i $. Then for $ a, b \in \ZZ $, the ideal $ \br{a, b} $ is generated by the gcd $ \br{a, b} $, by Theorem \ref{thm:6} below.
\end{note*}
\begin{definition}
$ n \in \ZZ $ is \textbf{prime} if $ n $ has exactly two positive divisors, namely $ 1 $ and $ n $.
\end{definition}
\begin{note*}
Frequently when people talk about prime numbers they restrict to the positive case. If we write, let $ p $ be a prime number, then we will usually mean $ p > 0 $.
\end{note*}
\begin{note*}
$ 1 $ is not prime.
\end{note*}
\subsection{Euclid's algorithm}
\begin{proposition}
If $ a, b \in \ZZ $, not both zero, then for any $ n \in \ZZ $, $ \br{a, b} = \br{a, b - na} $.
\end{proposition}
\begin{proof}
By definition, it is enough to show that if $ r \mid a $ and $ r \mid b $ then $ r \mid a $ and $ r \mid b - na $ and conversely.
\end{proof}
\begin{theorem}
\label{thm:5}
Let $ a, b \in \ZZ $ with $ b > 0 $. Then there exist unique $ q, r \in \ZZ $ with $ 0 \le r < b $ and $ a = qb + r $.
\end{theorem}
\begin{proof}
Take $ q = \fbr{a / b} $. By definition $ 0 \le a / b - q < 1 $, that is $ 0 \le a - qb < b $, so take $ r = a - qb $. Uniqueness is easy.
\end{proof}
\textbf{Euclid's algorithm} is as follows. Let $ a, b \in \ZZ $ not both zero. Without loss of generality, $ 0 \le b \le a $.
\begin{enumerate}[leftmargin=0.5in, label=Step \arabic*.]
\item If $ b = 0 $, output $ a $.
\item Otherwise, replace $ \br{a, b} $ with $ \br{b, r} $ as in Theorem \ref{thm:5}. Then go to step 1.
\end{enumerate}
This algorithm terminates because $ \abs{a} + \abs{b} $ decreases when we apply step $ 2 $.
\begin{example*}
\hfill
\begin{minipage}{0.5\textwidth}
\begin{align*}
\br{120, 87}
& = \br{87, 33} & 120 = 87 + 33 \\
& = \br{33, 21} & 87 = 2\br{33} + 21 \\
& = \br{21, 12} & 33 = 21 + 12 \\
& = \br{12, 9} & 21 = 12 + 9 \\
& = \br{9, 3} & 12 = 9 + 3 \\
& = \br{3, 0} & 9 = 3\br{3} + 10.
\end{align*}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{align*}
3
& = 12 - 9 \\
& = 12 - \br{21 - 12} \\
& = 2\br{12} - 21 \\
& = 2\br{33 - 21} - 21 \\
& = 2\br{33} - 3\br{21} \\
& = 2\br{33} - 3\br{87 - 2\br{33}} \\
& = 8\br{33} - 3\br{87} \\
& = 8\br{120 - 87} - 3\br{87} \\
& = 8\br{120} - 11\br{87}.
\end{align*}
\end{minipage}
\end{example*}
\begin{theorem}
\label{thm:6}
If $ a, b \in \ZZ $, not both zero, then there exist $ r, s \in \ZZ $ such that $ \br{a, b} = ra + sb $.
\end{theorem}
\begin{proof}
Idea is to write $ \br{a_n, b_n} $ for the sequence of pairs in Euclid's algorithm, and use downwards induction on $ n $. \footnote{Exercise}
\end{proof}
\pagebreak
\subsection{Unique factorisation}
\begin{proposition}
\label{prop:7}
Let $ n, a, b \in \ZZ $ with $ n \mid ab $ and $ \br{n, a} = 1 $. Then $ n \mid b $.
\end{proposition}
\begin{proof}
Since $ \br{n, a} = 1 $, we can write $ rn + sa = 1 $, so $ b = n\br{rb} + \br{ab}s $, which is divisible by $ n $.
\end{proof}
If $ \br{n, a} = 1 $, we say that $ n $ and $ a $ are \textbf{coprime}.
\lecture{2}{Tuesday}{09/10/18}
\begin{corollary}
\label{cor:8}
If $ p $ is prime and $ p \mid ab $ then $ p \mid a $ or $ p \mid b $.
\end{corollary}
\begin{proof}
If $ p \nmid a $ then $ \br{p, a} = 1 $, so Proposition \ref{prop:7} implies $ p \mid b $.
\end{proof}
\begin{proposition}
\label{prop:9}
If $ \br{a, b} = 1 $, and $ a \mid n $ and $ b \mid n $, then $ ab \mid n $.
\end{proposition}
\begin{proof}
By \ref{thm:6}, we can write $ 1 = ra + sb $ with $ r, s \in \ZZ $. So $ n = r\br{na} + s\br{nb} $, which is divisible by $ ab $.
\end{proof}
We say that $ m_1, \dots, m_n \in \ZZ $ are \textbf{pairwise coprime} if $ \br{m_i, m_j} = 1 $ for all $ i \ne j $.
\begin{corollary}
\label{cor:10}
If $ m_1, \dots, m_n $ are pairwise coprime and $ m_i \mid N $ for all $ i $ then $ m_1 \dots m_n \mid N $.
\end{corollary}
\begin{proof}
Induction on $ n $, where $ n = 2 $ is Proposition \ref{prop:9}. \footnote{Exercise}
\end{proof}
\begin{proposition}
\label{prop:11}
Every $ n \in \ZZ^* $ can be written as $ \pm p_1 \dots p_r $ where $ p_i $ are prime, and $ r $ could be zero.
\end{proposition}
\begin{proof}
Use induction on $ \abs{n} $. The case $ \abs{n} $ is trivial, so suppose $ \abs{n} > 1 $. Then either $ \abs{n} $ is prime, or $ \abs{n} = ab $ for $ 1 < a, b < \abs{n} $, and by induction each of $ a $ and $ b $ is a product of primes.
\end{proof}
\begin{theorem}
Every $ n \in \ZZ_{> 0} $ can be written as $ \pm p_1 \dots p_r $ where $ p_i $ are prime and are uniquely determined up to ordering.
\end{theorem}
\begin{proof}
Existence is Proposition \ref{prop:11}. Suppose that $ n = p_1 \dots p_r = q_1 \dots q_s $, with $ p_i $ and $ q_i $ prime. Then without loss of generality suppose $ r, s \ge 1 $. Then $ p_1 \mid p_1 \dots p_r $, so $ p_1 \mid q_1 \dots q_s $. By Corollary \ref{cor:8}, either $ p_1 \mid q_1 $ or $ p_1 \mid q_2 \dots q_s $. Proceeding inductively, eventually $ p_1 \mid q_i $ for some $ i $. Since $ q_i $ is prime this means $ p_1 = q_i $. We then have $ p_2 \dots p_r = q_1 \dots q_{i - 1}q_{i + 1} \dots q_s $. Since this product is smaller than $ n $, by the inductive hypothesis we must have $ r - 1 = s - 1 $ and the $ p_i $, except $ p_1 $, are a rearrangement of the $ q_j $, except $ q_i $.
\end{proof}
\subsection{Linear diophantine equations}
Let $ a, b, c \in \ZZ^* $. Want to solve
$$ ax + by = c, \qquad x, y \in \ZZ. $$
\begin{example*}
$ 2x + 6y = 3 $ has no solutions.
\end{example*}
In general, there are no solutions if $ \br{a, b} \nmid c $. Suppose that $ \br{a, b} \mid c $. Then
$$ ax + by = c \qquad \iff \qquad \dfrac{a}{\br{a, b}}x + \dfrac{b}{\br{a, b}}y = \dfrac{c}{\br{a, b}}. $$
By Theorem \ref{thm:6}, since $ \br{a / \br{a, b}, b / \br{a, b}} = 1 $, we can find $ r, s \in \ZZ $ with $ ar / \br{a, b} + bs / \br{a, b} = 1 $, so
$$ \dfrac{a}{\br{a, b}}\br{\dfrac{rc}{\br{a, b}}} + \dfrac{b}{\br{a, b}}\br{\dfrac{sc}{\br{a, b}}} = \dfrac{c}{\br{a, b}}. $$
So $ x = rc / \br{a, b} $ and $ y = sc / \br{a, b} $ is a solution. Then $ X $ and $ Y $ is another solution if and only if
$$ \dfrac{a}{\br{a, b}}X + \dfrac{b}{\br{a, b}}Y = \dfrac{a}{\br{a, b}}x + \dfrac{b}{\br{a, b}}y \qquad \iff \qquad \dfrac{a}{\br{a, b}} \ \Bigg| \ y - Y, \qquad \dfrac{b}{\br{a, b}} \ \Bigg| \ X - x. $$
See that the solutions are exactly
$$ X = x + \dfrac{nb}{\br{a, b}}, \qquad Y = y - \dfrac{na}{\br{a, b}}. $$
\pagebreak
\section{Congruences and modular arithmetic}
\subsection{Congruences}
\begin{definition}
Let $ n \in \ZZ^* $, usually $ n > 0 $. Let $ a, b \in \ZZ $. We say that $ a $ is \textbf{congruent to $ b \mod n $} if and only if $ n \mid a - b $. Write $ a \equiv b \mod n $.
\end{definition}
$ \equiv $ is an equivalence relation, and we write $ \ZZ / n\ZZ $ for the equivalence classes, which is a ring.
\begin{example*}
If $ a \equiv b \mod n $ and $ c \equiv d \mod n $, then
$$ a + c \equiv b + d \mod n, \qquad ac \equiv bd \mod n. $$
\end{example*}
If $ a \in \ZZ $, we sometimes write $ \overline{a} $ for the image of $ a $ in $ \ZZ / n\ZZ $.
\begin{example*}
If $ n = 12 $, then $ \overline{25} = \overline{1} $.
\end{example*}
So every element of $ \ZZ / n\ZZ $ is equal to $ \overline{r} $ for some unique $ r \in \cbr{0, \dots, n - 1} $. We often write
$$ \ZZ / n\ZZ = \cbr{0, \dots, n - 1}. $$
\begin{example*}
If $ n = 6 $, we could write $ 3 + 4 = 1 $ and $ 3 \times 4 = 0 $.
\end{example*}
Let $ R $ be a commutative ring with unity. Then a \textbf{unit} of $ R $ is an element $ x $ such that there exists $ y \in R $ with $ xy = 1 $. Write $ R^\times $ for the set of units in $ R $. This is a group under multiplication.
\begin{example*}
\hfill
\begin{itemize}
\item $ \ZZ^\times = \cbr{\pm 1} $.
\item $ \QQ^\times = \QQ \setminus \cbr{0} = \cbr{x \in \QQ \st x \ne 0} $.
\end{itemize}
\end{example*}
We want to understand $ \unit{n} $. Which elements of $ \cbr{0, \dots, n - 1} $ are in $ \unit{n} $? If $ r \in \ZZ $ and $ r \in \unit{n} $ then there exists $ s \in \ZZ $ such that $ rs \equiv 1 \mod n $. This implies that $ \br{r, n} = 1 $. Conversely, if $ \br{r, n} = 1 $, then there exist $ x, y \in \ZZ $ such that $ rx + ny = 1 $, that is $ rx \equiv 1 \mod n $, that is $ r $ is a unit. So
$$ \unit{n} = \cbr{0 \le i < n \st \br{i, n} = 1}. $$
\begin{example*}
If $ p $ is a prime, then
$$ \unit{p} = \cbr{1, \dots, p - 1}. $$
So $ \ZZ / p\ZZ $ is a ring with the property that every non-zero element has a multiplicative inverse, so it is a field. Another equivalent way to see this is to check that $ p\ZZ $ is a maximal ideal of $ \ZZ $.
\end{example*}
Thus every non-zero congruence class modulo $ p $ is a unit.
\pagebreak
\subsection{Linear congruence equations}
\lecture{3}{Wednesday}{10/10/18}
Consider the question of solving
$$ ax \equiv b \mod c, \qquad a, b, c, x \in \ZZ. $$
This is equivalent to solving
$$ ax + cy = b, \qquad y \in \ZZ. $$
We saw yesterday that this has solutions if and only if $ \br{a, c} \mid b $. Furthermore, there is a unique solution modulo $ c / \br{a, c} $, because all the solutions are obtained by adding multiples of $ c / \br{a, c} $ to our given $ x $, and subtracting the corresponding multiple of $ a / \br{a, c} $ from $ y $. This implies that there are $ \br{a, c} $ solutions to the original congruence modulo $ c $. If $ x_0 $ is one solution, the others are
$$ x_0 + \dfrac{cj}{\br{a, c}}, \qquad 0 \le j < \br{a, c}. $$
In particular, if $ \br{a, c} = 1 $ then there is a unique solution to $ ax \equiv b \mod c $. Indeed $ a \in \unit{c} $, so it has an inverse $ a^{-1} $, and $ x \equiv a^{-1}b \mod c $ is the unique solution.
\begin{example*}
\hfill
\begin{itemize}
\item $ 2x \equiv 3 \mod 6 $ has no solutions as $ \br{2, 6} = 2 \nmid 3 $.
\item $ 2x \equiv 4 \mod 6 $ if and only if $ x \equiv 2 \mod 3 $, which has solutions $ x \equiv 2 \mod 6 $ and $ x \equiv 5 \mod 6 $.
\end{itemize}
\end{example*}
\subsection{The Chinese remainder theorem}
\begin{theorem}[Chinese remainder theorem]
\label{thm:14}
Let $ m_1, \dots, m_n \in \ZZ_{> 0} $ be pairwise coprime. Then the natural map
$$ \ZZ / m_1 \dots m_n\ZZ \xrightarrow{\sim} \ZZ / m_1\ZZ \times \dots \times \ZZ / m_n\ZZ $$
is an isomorphism of rings. Consequently,
$$ \unit{m_1 \dots m_n} \xrightarrow{\sim} \unit{m_1} \times \dots \times \unit{m_n} $$
is an isomorphism of abelian groups.
\end{theorem}
\begin{remark*}
This is false without the assumption that $ m_i $ pairwise coprime, such as $ m_1 = m_2 = 2 $.
\end{remark*}
\begin{proof}
The map
$$ \ZZ / m_1 \dots m_n\ZZ \to \ZZ / m_1\ZZ \times \dots \times \ZZ / m_n\ZZ $$
is a ring homomorphism between two rings of order, or cardinality, $ m_1 \dots m_n $. So to show that it is an isomorphism, it is enough to show that it is an injection, so we only need to check that the kernel is zero. So we need to know that if $ m_i \mid N $ for all $ i $, then $ m_1 \dots m_n \mid N $. This is Corollary \ref{cor:10}. For the second part, just use that if $ R $ and $ S $ are rings, then
$$ \br{R \times S}^\times \cong R^\times \times S^\times. $$
\end{proof}
The first part says that given any $ a_i \in \ZZ $, there is a unique $ x \mod m_1 \dots m_n $ with $ x \equiv a_i \mod m_i $. Write
$$ M = m_1 \dots m_n, \qquad M_i = \dfrac{M}{m_i}. $$
Choose $ q_i $ such that $ q_iM_i \equiv 1 \mod m_i $, using $ \br{M_i, m_i} = 1 $ because $ \br{m_j, m_i} = 1 $ for all $ j \ne i $. Then take
$$ x = a_1q_1M_1 + \dots + a_nq_nM_n. $$
Then
$$ x \equiv a_iq_iM_i \equiv a_i \mod m_i. $$
\pagebreak
\section{The structure of \texorpdfstring{$ \unit{n} $}{Z/nZ}}
\subsection{The Euler \texorpdfstring{$ \Phi $}{Phi} function}
Let $ \Phi\br{n} $ be the order of $ \unit{n} $, that is
$$ \Phi\br{n} = \#\cbr{1 \le i < n \st \br{i, n} = 1}. $$
\begin{example*}
If $ p $ is prime, $ \Phi\br{p} = p - 1 $.
\end{example*}
$ \Phi $ is called \textbf{Euler's $ \Phi $ function}.
\begin{definition}
Let $ f $ be a function on the positive integers. Say that $ f $ is \textbf{strongly multiplicative} if
$$ f\br{mn} = f\br{m}f\br{n}, $$
for all $ m $ and $ n $. Say $ f $ is \textbf{multiplicative} if this holds whenever $ \br{m, n} = 1 $.
\end{definition}
$ \Phi $ is multiplicative by Theorem \ref{thm:14}, because if $ \br{m, n} = 1 $ then
$$ \unit{mn} \xrightarrow{\sim} \unit{m} \times \unit{n}. $$
$ \Phi $ is not strongly multiplicative, since $ \Phi\br{4} = 2 \ne 1 = \Phi\br{2}\Phi\br{2} $. Write $ n = \prod_i p_i^{a_i} $, where $ p_i $ are distinct primes. Then $ \Phi\br{n} = \prod_i \Phi\br{p_i^{a_i}} $. If $ p $ is prime then
$$ \Phi\br{p^a} = \#\cbr{1 \le i < p^a \st \br{i, p^a} = 1} = \#\cbr{1 \le i < p^a \st p \nmid i} = p^a - p^{a - 1} = p^a\br{1 - \dfrac{1}{p}}. $$
If $ n = \prod_i p_i^{a_i} $, then
$$ \Phi\br{n} = \prod_i \Phi\br{p_i^{a_i}} = \prod_i p_i^{a_i}\br{1 - \dfrac{1}{p_i}} = n\prod_i \br{1 - \dfrac{1}{p_i}} = n\prod_{p \mid n} \br{1 - \dfrac{1}{p}}. $$
\subsection{Euler's theorem}
\begin{theorem}[Euler's theorem]
\label{thm:16}
If $ \br{a, n} = 1 $, then
$$ a^{\Phi\br{n}} \equiv 1 \mod n. $$
\end{theorem}
\begin{proof}
This is equivalent to showing that $ \overline{a}^{\Phi\br{n}} = 1 $ in $ \unit{n} $. This is a group of order $ \Phi\br{n} $, so this is immediate from Lagrange's theorem.
\end{proof}
\begin{corollary}[Fermat's little theorem]
If $ p $ is prime and $ p \nmid a $, then
$$ a^{p - 1} \equiv 1 \mod p. $$
\end{corollary}
\begin{proof}
Theorem \ref{thm:16} with $ n = p $, so $ \Phi\br{n} = p - 1 $.
\end{proof}
Next, want to understand the structure of $ \unit{n} $. By Theorem \ref{thm:14}, it is enough to study the case that $ n $ is a prime power. We will begin by considering the case that $ n $ is prime.
\begin{example*}
Let $ n = 5 $. Then$ \unit{5} = \cbr{1, 2, 3, 4} $. This has order four. So it is either cyclic of order four or a product of two cyclic groups of order two. Since $ 2^2 = 4 $, $ 2^3 = 3 $, and $ 2^4 = 1 $, $ \unit{5} $ is cyclic of order four.
\end{example*}
Next, $ \unit{p} $ is cyclic of order $ p - 1 $ for any prime $ p $.
\lecture{4}{Friday}{12/10/18}
\begin{definition}
If $ G $ is a group and $ g \in G $ is an element, the \textbf{order} of $ g $ is the least $ a \ge 1 $ such that $ g^a = 1 $. In particular, if $ \br{g, n} = 1 $, then we write $ \ord_n g $ for the order of $ g $ in $ \unit{n} $, the \textbf{order of $ g $ modulo $ n $}.
\end{definition}
\begin{proposition}
\label{prop:19}
If $ G $ is a group and $ g $ is an element of order $ a $, then $ g^n = 1 $ if and only if $ a \mid n $.
\end{proposition}
\begin{proof}
If $ n = ab $ then $ g^n = \br{g^a}^b = 1^b = 1 $. Conversely, write $ n = ab + r $ with $ 0 \le r < a $. Then $ g^r = 1 $ and since $ r < a $ we have $ r = 0 $.
\end{proof}
\pagebreak
In particular, if $ \br{g, n} = 1 $, then $ g^{\Phi\br{n}} = 1 $, by Euler's theorem, so Proposition \ref{prop:19} implies that $ \ord_n g \mid \Phi\br{n} $. We want to prove that if $ p $ is prime, then $ \unit{p} $ is cyclic. Equivalently, we need to show that there exists $ g $ such that $ \ord_p g = \Phi\br{p} = p - 1 $. We will do this by counting the number of elements of each order. The key point is that $ \ZZ / p\ZZ $ is a field. For any $ d \ge 1 $, the elements of $ \unit{p} $ of order dividing $ d $ are exactly the roots of the $ X^d - 1 $ in $ \ZZ / p\ZZ $, by Proposition \ref{prop:19}.
\begin{example*}
The equation $ X^2 = 1 $ has exactly two solutions modulo $ p $ for any prime $ p $, namely $ \pm 1 $, but it can have more modulo $ n $ if $ n $ is composite. For example, if $ n = 15 $, then $ 4 $ and $ 11 $ are also solutions, since $ X^2 - 1 \equiv 0 \mod n $ if and only if $ n \mid \br{X + 1}\br{X - 1} $, for example $ 15 \mid \br{4 + 1}\br{4 - 1} $.
\end{example*}
\begin{definition}
$ g \in \ZZ $ with $ \br{g, p} = 1 $ is a \textbf{primitive root} if $ \ord_p g = p - 1 $, that is $ \unit{p} = \abr{g} $.
\end{definition}
\begin{lemma}
\label{lem:21}
Let $ R $ be a commutative ring, and let $ P\br{X} \in R\sbr{X} $. If $ \alpha \in R $ has $ P\br{\alpha} = 0 $, then there exists $ Q\br{X} \in R\sbr{X} $ such that $ P\br{X} = \br{X - \alpha}Q\br{X} $.
\end{lemma}
\begin{example*}
If $ R = \ZZ / 15\ZZ $, $ X^2 - 1 = \br{X + 1}\br{X - 1} = \br{X + 4}\br{X - 4} $.
\end{example*}
\begin{proof}
Induction on $ \deg P $, where $ \deg P = 0 $ is obvious. Let $ \deg P = d $, and assume the result holds for degree at most $ d - 1 $. Let $ P\br{X} = cX^d + \dots $ and $ S\br{X} = P\br{X} - cX^{d - 1}\br{X - \alpha} $. Then $ S\br{X} $ has degree at most $ d - 1 $. Also $ S\br{\alpha} = 0 $. By induction, we can write $ S\br{X} = \br{X - \alpha}R\br{X} $. Set $ Q\br{X} = cX^{d - 1} + R\br{X} $. Then $ \br{X - \alpha}Q\br{X} = cX^{d - 1}\br{X - \alpha} + S\br{X} = P\br{X} $.
\end{proof}
\begin{theorem}
\label{thm:22}
Let $ F $ be a field. Let $ P\br{X} $ be a polynomial in $ F\sbr{X} $. Then $ P\br{X} $ has at most $ d $ distinct roots in $ F $.
\end{theorem}
\begin{proof}
Induction on $ d = \deg P $, where $ d = 1 $ is obvious. If $ P $ has no roots, then we are done. Otherwise, let $ \alpha $ be a root. By Lemma \ref{lem:21}, $ P\br{X} = \br{X - \alpha}Q\br{X} $, and $ Q\br{X} $ has degree $ d - 1 $, so we are done by induction.
\end{proof}
\begin{corollary}
\label{cor:23}
Let $ d $ be any divisor of $ p - 1 $. Then there are exactly $ d $ elements of $ \unit{p} $ of order dividing $ d $.
\end{corollary}
\begin{proof}
We have to show that $ X^d - 1 $ has exactly $ d $ roots in $ \ZZ / p\ZZ $. By Fermat's little theorem, $ X^{p - 1} - 1 $ has exactly $ p - 1 $ roots. Since $ d \mid p - 1 $, we can write
$$ X^{p - 1} - 1 = \br{X^d - 1}\br{\br{X^d}^{\tfrac{p - 1}{d} - 1} + \dots + 1} = \br{X^d - 1}Q\br{X}, \qquad \deg Q = p - 1 - d. $$
Then $ X^{p - 1} - 1 $ has exactly $ p - 1 $ roots, $ X^d - 1 $ has at most $ d $ roots, and $ Q\br{X} $ has at most $ p - 1 - d $ roots, by Theorem \ref{thm:22}. So $ X^d - 1 $ has exactly $ d $ roots.
\end{proof}
\begin{example*}
Let $ p = 7 $. There are
\begin{itemize}
\item one element of order one,
\item two elements of order dividing two, so one element of order two,
\item three elements of order dividing three, so two elements of order three, and
\item six elements of order dividing six, so two elements of order six.
\end{itemize}
\end{example*}
\begin{lemma}
\label{lem:24}
For any $ n \ge 1 $, we have
$$ \sum_{d \mid n} \Phi\br{d} = n. $$
\end{lemma}
\begin{proof}
For each $ d \mid n $, the elements of $ \cbr{1, \dots, n} $ with $ \br{i, n} = n / d $ are exactly those of the form $ i = \br{n / d}j $ for $ 1 \le j \le d $ and $ \br{j, d} = 1 $. There are exactly $ \Phi\br{d} $ such elements. Since the $ n / d $ run over all the divisors of $ n $, we are done.
\end{proof}
\pagebreak
\begin{theorem}
\label{thm:25}
Let $ p $ be prime, and let $ d \mid p - 1 $. Then there are exactly $ \Phi\br{d} $ elements of $ \unit{p} $ of order $ d $. In particular, there are $ \Phi\br{p - 1} $ primitive roots, and $ \unit{p} $ is cyclic.
\end{theorem}
\begin{proof}
Induction on $ d $, where $ d = 1 $ is obvious. Assume the result holds for all $ d' \mid d $ and $ d' \ne d $. Then by Lemma \ref{lem:24},
$$ \Phi\br{d} = d - \sum_{d' \mid d, \ d' \ne d} \Phi\br{d'}. $$
Now use the inductive hypothesis and Corollary \ref{cor:23}.
\end{proof}
\lecture{5}{Tuesday}{16/10/18}
\begin{proposition}
Let $ p $ be an odd prime and $ n \ge 1 $. Then $ \unit{p^n} $ is cyclic.
\end{proposition}
\begin{proof}
Consider three cases.
\begin{itemize}[leftmargin=0.5in]
\item[$ n = 1 $.] Theorem \ref{thm:25}.
\item[$ n = 2 $.] Let $ g $ be a primitive root modulo $ p $. Claim that either $ g^{p - 1} \not\equiv 1 \mod p^2 $ and $ g $ is a generator for $ \unit{p^2} $, or $ g^{p - 1} \equiv 1 \mod p^2 $ and $ g + p $ is a generator for $ \unit{p^2} $. Either way, $ \unit{p^2} $ is cyclic. Suppose firstly that
$$ g^{p - 1} \not\equiv 1 \mod p^2. $$
Then $ \#\unit{p^2} = \Phi\br{p^2} = p\br{p - 1} $. So $ \ord_{p^2} g \mid p\br{p - 1} $. On the other hand, $ g^{\ord_{p^2} g} \equiv 1 \mod p^2 $, so $ g^{\ord_{p^2} g} \equiv 1 \mod p $, so $ p - 1 \mid \ord_{p^2} g $, because $ \ord_p g = p - 1 $ by assumption. But $ \ord_{p^2} g \ne p - 1 $, as $ g^{p - 1} \not\equiv 1 \mod p^2 $. So $ \ord_{p^2} g = p\br{p - 1} $, as required. Suppose now that
$$ g^{p - 1} \equiv 1 \mod p^2. $$
It suffices to show that $ \br{g + p}^{p - 1} \not\equiv 1 \mod p^2 $, as we can then apply the analysis above with $ g + p $ in place of $ g $. By the binomial theorem,
$$ \br{g + p}^{p - 1} \equiv g^{p - 1} + \br{p - 1}g^{p - 2}p \equiv 1 + \br{p - 1}g^{p - 2}p \mod p^2. $$
Since $ p \nmid \br{p - 1}g^{p - 2} $, $ \br{g + p}^{p - 1} \not\equiv 1 \mod p^2 $, as required.
\item[$ n \ge 2 $.] It suffices to show that if $ \ord_{p^2} g = p\br{p - 1} $, then $ \ord_{p^n} g = p^{n - 1}\br{p - 1} $. We do this by induction on $ n $. So assume that $ \ord_{p^n} g = p^{n - 1}\br{p - 1} $. Then $ \ord_{p^n} g \mid \ord_{p^{n + 1}} g $, and $ \ord_{p^{n + 1}} g \mid \Phi\br{p^{n + 1}} = p^n\br{p - 1} $. So either $ \ord_{p^{n + 1}} g = p^n\br{p - 1} $, or $ \ord_{p^{n + 1}} g = p^{n - 1}\br{p - 1} $. So we need to show that
$$ g^{p^{n - 1}\br{p - 1}} \not\equiv 1 \mod p^{n + 1}. $$
To do this, consider $ g^{p^{n - 2}\br{p - 1}} $ modulo $ p^{n - 1} $ and modulo $ p^n $. Since $ \Phi\br{p^{n - 1}} = p^{n - 2}\br{p - 1} $, by Euler's theorem, $ g^{p^{n - 2}\br{p - 1}} \equiv 1 \mod p^{n - 1} $. Write $ g^{p^{n - 2}\br{p - 1}} = 1 + p^{n - 1}t $. Since $ \ord_{p^n} g = p^{n - 1}\br{p - 1} $ by assumption, $ g^{p^{n - 2}\br{p - 1}} \not\equiv 1 \mod p^n $, that is $ p \nmid t $. Then
\begin{align*}
g^{p^{n - 1}\br{p - 1}}
& = \br{g^{p^{n - 2}\br{p - 1}}}^p
= \br{1 + p^{n - 1}t}^p
= 1 + p^nt + \binom{p}{2}p^{2\br{n - 1}}t^2 + \dots + p^{p\br{n - 1}}t^p \\
& \equiv 1 + p^nt \mod p^{n + 1},
\end{align*}
since $ r\br{n - 1} \ge n + 1 $ if and only if $ \br{r - 1}n \ge r + 1 $ and $ p > 2 $, so
$$ p^{n + 1} \ \Bigg| \ p^{2n - 1} = p^{2\br{n - 1} + 1} \ \Bigg| \ \binom{p}{2}p^{2\br{n - 1}}. $$
So $ g^{p^{n - 1}\br{p - 1}} \not\equiv 1 \mod p^{n + 1} $, because $ p \nmid t $.
\end{itemize}
\end{proof}
\begin{example*}
\hfill
\begin{itemize}
\item $ \unit{2} = \cbr{1} $.
\item $ \unit{4} = \cbr{1, 3} $ is cyclic of order two, with $ 3 $ as a generator.
\item $ \unit{8} = \cbr{1, 3, 5, 7} $ is not cyclic, since $ 1^2 \equiv 3^2 \equiv 5^2 \equiv 7^2 \equiv 1 \mod 8 $, so every element has order two.
\end{itemize}
\end{example*}
\pagebreak
\begin{lemma}
\label{lem:27}
For $ n \ge 0 $ we have
$$ 5^{2^n} \equiv 1 + 2^{n + 2} \mod 2^{n + 3}. $$
\end{lemma}
\begin{proof}
Induction on $ n $, where $ n = 0 $ is obvious. Assume that $ 5^{2^n} = 1 + 2^{n + 2}t $ with $ t $ odd. Then
$$ 5^{2^{n + 1}} = \br{1 + 2^{n + 1}t}^2 = 1 + 2^{n + 3}t + 2^{2\br{n + 2}}t^2 = 1 + 2^{n + 3}\br{t + 2^{n + 1}t^2}, $$
where $ t + 2^{n + 1}t^2 $ is odd.
\end{proof}
\begin{proposition}
If $ n \ge 2 $ then there is an isomorphism
$$ \unit{2^n} \xrightarrow{\sim} \ZZ / 2\ZZ \times \ZZ / 2^{n - 2}\ZZ. $$
In particular, if $ n \ge 3 $, then $ \unit{2^n} $ is not cyclic.
\end{proposition}
\begin{proof}
Let $ \abr{g} $ denote the group $ \cbr{1, \dots, g^{\ord g - 1}} $ generated by $ g $. Consider the natural map
$$ \abr{-1} \times \abr{5} \to \unit{2^n}. $$
This is injective, because if $ \pm 1\br{5}^s \equiv 1 \mod 2^n $ then in particular $ \pm 1\br{5}^s \equiv 1 \mod 4 $ so $ \pm 1 \equiv 1 \mod 4 $, so we must have $ 5^s \equiv 1 \mod 2^n $, that is $ 5^s = 1 $ in $ \abr{5} $. Then $ \abr{-1} $ has order $ 2 $ and $ \abr{5} $ has order $ \ord_{2^n} 5 = 2^{n - 2} $ by Lemma \ref{lem:27}. So $ \abr{-1} \times \abr{5} $ has order $ 2\br{2^{n - 2}} = 2^{n - 1} = \Phi\br{2^n} = \#\unit{2^n} $. So the map $ \abr{-1} \times \abr{5} \to \unit{2^n} $ is an injection of groups of the same order, so it is a bijection.
\end{proof}
\begin{theorem}
$ \unit{n} $ is cyclic if and only if either
\begin{itemize}
\item $ n = 1, 2, 4 $,
\item $ n = p^r $ for $ p > 2 $ prime and $ r \ge 1 $, or
\item $ n = 2p^r $ for $ p > 2 $ prime and $ r \ge 1 $.
\end{itemize}
\end{theorem}
\lecture{6}{Wednesday}{17/10/18}
Primitive roots are generators of $ \unit{n} $. Find them in practice by guessing small values of $ g $, and seeing if $ g $ is a generator. There are $ \Phi\br{p - 1} $ primitive roots, which means that you have a high probability of success. Could work out $ 1, \dots, g^{p - 2} $ and check these are distinct. This would be inefficient. Better is to check for some prime $ q \mid p - 1 $ whether $ g^{\br{p - 1} / q} = 1 $ or not. This works, because if $ g^{\br{p - 1} / q} = 1 $ then $ g $ is not a primitive root, while if $ g^{\br{p - 1} / q} \ne 1 $ then $ \ord_p g \mid p - 1 $ and $ \ord_p g \nmid \br{p - 1} / q $. If this holds for all $ q \mid p - 1 $, then $ \ord_p g = p - 1 $, because otherwise it would be a proper divisor, and so would divide $ \br{p - 1} / q $ for some prime $ q \mid p - 1 $.
\begin{example*}
Let $ p = 31 $, so $ p - 1 = 30 = \br{2}\br{3}\br{5} $. Then $ g $ is a primitive root if and only if
$$ g^{15} \ne 1, \qquad g^{10} \ne 1, \qquad g^{6} \ne 1. $$
\begin{itemize}
\item Is $ 2 $ a primitive root? $ 2^2 = 4, 2^4 = 16, 2^6 = 2 $, but $ 2^{10} = 2^{15} = 1 $ because $ 2^5 = 32 = 1 $.
\item How about $ 3 $? $ 3^2 = 9, 3^4 = 19, 3^6 = 16, 3^8 = 20, 3^{10} = 25, 3^{15} = 30 $. So $ 3 $ is a primitive root modulo $ 31 $.
\end{itemize}
\end{example*}
\pagebreak
\section{Primality testing and factorisation}
The idea is that testing whether $ n \in \ZZ $ is prime is easy. Factoring $ n $ is expected to be hard. Easy here means that there is an algorithm to check whether $ n $ is prime or not which runs in time polynomial in $ \log n $. It is known that a deterministic algorithm exists to do this, the \textbf{Agrawal-Kayal-Saxena (AKS) algorithm}, in 2005. We will see an algorithm that runs faster than this in practice. On the other hand, for factoring there are algorithms which are better than exponential in $ \log n $, but there is nothing close to polynomial time, and the general expectation is that no such algorithm should exist.
\subsection{Factorisation}
How do we factor three digit numbers, or small four digit numbers, say at most $ 400 $ if we wanted to factor with a paper or a calculator? If $ n \le 400 $ and $ n $ is composite, then it has a prime factor at most $ \sqrt{400} = 20 $, since if $ d \mid n $ then $ d\br{n / d} = n $, so either $ d \le \sqrt{n} $ or $ n / d \le \sqrt{n} $. So you only have to be able to check for divisibility by
$$ 2, \quad 3, \quad 5, \quad 7, \quad 11, \quad 13, \quad 17, \quad 19. $$
\begin{itemize}[leftmargin=0.75in]
\item[$ 2, 5 $.] Checking for divisibility is easy, by just looking at the last digit.
\item[$ 3, 11 $.] Use that $ 10 \equiv 1 \mod 3 $ and $ 10 \equiv -1 \mod 3 $. So
$$ \sum_i a_i10^i \equiv \sum_i a_i \mod 3, \qquad \sum_i a_i10^i \equiv \sum_i a_i\br{-1}^i \mod 11. $$
So you can check divisibility by $ 3 $, or $ 9 $, by checking for the sum of the digits, and $ 11 $ by taking the alternating sum.
\item[$ 7 $.] $ 10x + y \equiv 0 \mod 7 $ if and only if $ -2\br{10x + y} \equiv 0 \mod 7 $, if and only if $ x - 2y \equiv 0 \mod 7 $.
\item[$ 13, 17, 19 $.] There are no good tests.
\end{itemize}
If $ n \le 400 $ and $ n $ is not divisible by $ 2, 3, 5, 7, 11 $, then the smallest prime factor of $ n $ is at least $ 13 $. Since $ 13^3 > 400 $, it can have at most two prime factors. So if you want to factor numbers at most $ 400 $, you only have to remember a short list
$$ 13^2, \quad 13\br{17}, \quad 13\br{19}, \quad 13\br{23}, \quad 13\br{29}, \quad 17^2, \quad 17\br{19}, \quad 17\br{23}, \quad 19^2. $$
\begin{example*}
\hfill
\begin{itemize}
\item $ 143 \equiv 1 - 4 + 3 \equiv 0 \mod 11 $.
\item $ 144 \equiv 1 + 4 + 4 \equiv 0 \mod 9 $.
\item $ 154 \equiv 15 - 2\br{4} = 7 \equiv 0 \mod 7 $.
\end{itemize}
\end{example*}
\lecture{7}{Friday}{19/10/18}
Factor four digit numbers by an algorithm due to Fermat. The idea is to first check for small prime factors by hand, say $ p = 2, \dots, 19 $. If $ n $ is composite and does not have any small factors, then the prime factors of $ n $ should be close to $ \sqrt{n} $. If $ n = ab $ for $ a $ and $ b $ odd and $ a \le b $, then
$$ n = ab = \br{\dfrac{a + b}{2}}^2 - \br{\dfrac{b - a}{2}}^2, \qquad \br{\dfrac{a + b}{2}}^2 - n = \br{\dfrac{b - a}{2}}^2. $$
If you know $ \br{a + b} / 2 $ and $ \br{b - a} / 2 $, you can recover $ a $ and $ b $. So take $ m $ such that $ m^2 \le n < \br{m + 1}^2 $. If $ n = m^2 $, done. Otherwise check if $ \br{m + i}^2 - n $ is a square for increasing $ i $.
\begin{example*}
Let $ n = 6077 $. Then $ 77^2 < 6077 < 78^2 $, so
\begin{align*}
78^2 - 6077 & = 7, \\
79^2 - 6077 & = 164, \\
80^2 - 6077 & = 323, \\
81^2 - 6077 & = 484 = 22^2.
\end{align*}
Thus $ 6077 = 81^2 - 22^2 = \br{103}\br{59} $.
\end{example*}
\pagebreak
There exist algorithms for factoring $ n $ which run in better than exponential time in $ \log n $, such as the quadratic sieve and the general number field sieve.
\begin{example*}
Let $ n = 1649 $. Then $ 40^2 < 1649 < 41^2 $, so
\begin{align*}
41^2 - 1649 & = 32 = 2^5, \\
42^2 - 1649 & = 115, \\
43^2 - 1649 & = 200 = \br{2}^3\br{5}^2.
\end{align*}
Since $ 41^2 \equiv 2^5 \mod 1649 $ and $ 43^2 \equiv \br{2}^3\br{5}^2 \mod 1649 $,
$$ 80^2 \equiv \br{41}^2\br{43}^2 = 1763^2 \equiv 114^2 \mod 1649. $$
Then
$$ 0 \equiv 114^2 - 80^2 = \br{194}\br{34} = \br{2}^2\br{17}\br{97} \mod 1649. $$
In fact, $ 1649 = \br{17}\br{97} $. Better for this last step would be to have computed
$$ \br{194, 1649} = 97, \qquad \br{34, 1649} = 17. $$
Can do this quickly using Euclid's algorithm. To make this into an efficient algorithm, need to have a way given $ x_1, \dots, x_r $ to find a subset whose product is a square. If we know the prime factorisation for the $ x_i $, we can write
$$ x_i = p_1^{a_{i1}} \dots p_k^{a_{ik}}. $$
Want to choose $ \epsilon_i = 0, 1 $ such that $ \prod_{i = 1}^r x_i^{\epsilon_i} $ is a square. Equivalently, for each $ j $, want the exponent of $ p_j $ to be even, that is
$$ \sum_{i = 1}^r \epsilon_ia_{ij} \equiv 0 \mod 2. $$
Let
$$ x_1 = 2^5, \qquad x_2 = \br{5}\br{23}, \qquad x_3 = \br{2}^3\br{5}^2, \qquad p_1 = 2, \qquad p_2 = 5, \qquad p_3 = 23. $$
Ignore all numbers with a large prime factor, so here ignore $ 23 $. Then
$$ \onebytwo{\epsilon_1}{\epsilon_2}\twobytwo{5}{0}{3}{2} \equiv \onebytwo{0}{0} \mod 2 \qquad \iff \qquad \onebytwo{\epsilon_1}{\epsilon_2}\twobytwo{1}{0}{1}{0} = \onebytwo{0}{0} $$
in $ \ZZ / 2\ZZ $, a field $ \FF_2 $, that is $ \epsilon_1 + \epsilon_2 = 0 $, so $ \epsilon_1 = \epsilon_2 = 1 $.
\end{example*}
This step, solving linear equations in $ \ZZ / 2\ZZ $, can be done efficiently. The remaining difficulty is to find a supply of $ m \in \ZZ $ such that $ m^2 - n $ has only small prime factors. The idea is that if we fix a list of small primes to start with, we get congruence conditions on $ m $. It turns out that there is a straightforward algorithm for solving $ m^2 \equiv n \mod p $. This gives two possible values for $ m \mod p $. If you do this for lots of primes $ p $, you get a supply of congruence conditions for $ m $, so you can eliminate ever considering $ m $ such that $ m^2 - n $ has large prime factors.
\begin{example*}
$ m^2 = 1649 \equiv 2 \mod 3 $ has no solutions.
\end{example*}
\subsection{Testing primality}
\lecture{8}{Tuesday}{23/10/18}
Euler's theorem states that if $ \br{a, n} = 1 $ then $ a^{\Phi\br{n}} \equiv 1 \mod n $. In particular if $ p $ is prime then $ a^{p - 1} \equiv 1 \mod p $ for $ 1 \le a \le p - 1 $. In particular, if $ 2^{n - 1} \not\equiv 1 \mod n $, then $ n $ cannot be prime. The problem is that there exists $ n $ composite such that $ a^{n - 1} \equiv 1 \mod n $ for all $ \br{a, n} = 1 $, the \textbf{Carmichael numbers}. It is known that infinitely many of these exist. The \textbf{Miller-Rabin test} is a test for whether odd $ n \in \ZZ $ is prime or not. Today let $ n \equiv 3 \mod 4 $. Example sheet is $ n \equiv 1 \mod 4 $.
\begin{lemma}
\label{lem:30}
Let $ n > 1 $ be congruent to $ 3 \mod 4 $. Then $ n $ is prime if and only if
$$ a^{\tfrac{n - 1}{2}} \equiv \pm 1 \mod n, \qquad \br{a, n} = 1. $$
\end{lemma}
\pagebreak
\begin{proof}
\hfill
\begin{itemize}
\item If $ n $ is prime, then $ a^{n - 1} \equiv 1 \mod n $ by Fermat's little theorem, so $ \br{a^{\br{n - 1} / 2}}^2 \equiv 1 \mod n $, so $ a^{\br{n - 1} / 2} \equiv \pm 1 \mod n $.
\item Suppose firstly that $ n = p^k $ with $ p $ prime, and $ k \ge 2 $. Try
$$ a = 1 + p. $$
Then
$$ a^{\tfrac{n - 1}{2}} \equiv 1 + \br{\dfrac{n - 1}{2}}p \mod p^2, $$
by the binomial theorem. If $ a^{\br{n - 1} / 2} \equiv \pm 1 \mod n $, then
$$ \pm 1 \equiv a^{\tfrac{n - 1}{2}} \equiv 1 + \br{\dfrac{n - 1}{2}}p \equiv 1 \mod p, $$
so
$$ 1 \equiv 1 + \br{\dfrac{n - 1}{2}}p \mod p^2, $$
then $ p \mid \br{n - 1} / 2 $, so $ p \mid n - 1 $. But $ p \mid n $, a contradiction.
\item The remaining case is that $ n $ is composite but not a power of a prime. Write $ n = rs $ for $ r, s > 1 $, and odd, and $ \br{r, s} = 1 $. By the Chinese remainder theorem,
$$ \ZZ / n\ZZ \cong \ZZ / r\ZZ \times \ZZ / s\ZZ. $$
Choose $ a $ such that
$$ a \equiv -1 \mod r, \qquad a \equiv 1 \mod s. $$
Then $ \br{a, r} = \br{a, s} = 1 $, so $ \br{a, n} = 1 $. Since $ n \equiv 3 \mod 4 $, $ \br{n - 1} / 2 $ is odd, so
$$ a^{\tfrac{n - 1}{2}} \equiv -1 \mod r, \qquad a^{\tfrac{n - 1}{2}} \equiv 1 \mod s. $$
So $ a^{\br{n - 1} / 2} \not\equiv \pm 1 \mod n $.
\end{itemize}
\end{proof}
\begin{lemma}
\label{lem:31}
Suppose that $ n \equiv 3 \mod 4 $ is composite. Then the set of $ a \in \unit{n} $ which satisfy $ a^{\br{n - 1} / 2} \equiv \pm 1 \mod n $ is a proper subgroup of $ \unit{n} $.
\end{lemma}
\begin{proof}
Certainly $ 1^{\br{n - 1} / 2} \equiv 1 \mod n $. If $ a^{\br{n - 1} / 2} \equiv \pm 1 \mod n $ and $ b^{\br{n - 1} / 2} \equiv \pm 1 \mod n $,
$$ \br{ab}^{\tfrac{n - 1}{2}} \equiv a^{\tfrac{n - 1}{2}}b^{\tfrac{n - 1}{2}} \equiv \br{\pm 1}\br{\pm 1} \equiv \pm 1 \mod n, \qquad \br{a^{-1}}^{\tfrac{n - 1}{2}} \equiv \br{a^{\tfrac{n - 1}{2}}}^{-1} \equiv \br{\pm 1}^{-1} \equiv \pm 1 \mod n. $$
So this set is a subgroup of $ \unit{n} $. It is a proper subgroup by Lemma \ref{lem:30}.
\end{proof}
\begin{corollary}
At most half the elements of $ \unit{n} $ satisfy $ a^{\br{n - 1} / 2} \equiv \pm 1 \mod n $.
\end{corollary}
\begin{proof}
The set of such elements is a proper subgroup of $ \unit{n} $ by Lemma \ref{lem:31}, so it has index at least two.
\end{proof}
In fact, with a bit more work, you can improve this to show that at least $ \tfrac{3}{4} $ of the numbers $ 1 \le a \le n - 1 $ satisfy $ a^{\br{n - 1} / 2} \not\equiv \pm 1 \mod n $. So if you randomly choose numbers $ 1 \le a \le n - 1 $ $ x $ times, and $ n $ is composite, the probability that you find some $ a $ with $ a^{\br{n - 1} / 2} \not\equiv \pm 1 \mod n $ is at least $ 1 - \br{\tfrac{1}{4}}^x $. This gives a probabilistic algorithm to check if $ n $ is prime in polynomial time. If you assume the generalised Riemann hypothesis (GRH) you can find some
$$ 1 \le a \le \left\lceil 2 \br{\log n}^2 \right\rceil, \qquad a^{\tfrac{n - 1}{2}} \not\equiv \pm 1 \mod n. $$
In practice it is even better.
\begin{example*}
If $ n < 341550071728321 $, then one of $ a = 2, 3, 5, 7, 11, 13, 17 $ will work.
\end{example*}
\pagebreak
\section{Public-key cryptography}
Public-key cryptography is private communication and identity verification.
\subsection{Messages as sequences of classes modulo \texorpdfstring{$ n $}{n}}
How do we turn messages into numbers in $ \ZZ / n\ZZ $? The idea is to choose $ n $ very large. Say $ n > 2^{8k} $. Write down your message. Break it up into strings of at most $ k $ characters. Encode each character as an $ 8 $ bit binary number. String these integers together to get an $ 8k $ bit binary number. Regard that as an integer modulo $ n $.
\subsection{The Rivest-Shamir-Adleman (RSA) algorithm}
Now apply some function $ f : \ZZ / n\ZZ \to \ZZ / n\ZZ $, and then tell whoever you are trying to communicate with the result of this computation. Then they should apply some other function $ g : \ZZ / m\ZZ \to \ZZ / n\ZZ $, to get back the number you started with. So want $ f $ to be injective. Want to be able to make $ f $ public without making $ g $ public. The idea is to choose two large prime numbers $ p $ and $ q $ and set $ n = pq $. Choose $ \br{e, \Phi\br{n}} = 1 $. Find $ d $ such that
$$ de = 1 \mod \Phi\br{n} = \br{p - 1}\br{q - 1} = n - \br{p + q} + 1. $$
Publish $ n $ and $ e $, and you keep $ p, q, \Phi\br{n}, d $ secret. Let $ f\br{x} = x^e \mod n $ and $ g\br{x} = x^d \mod n $. Then
$$ \br{x^e}^d \equiv x^{de} \equiv x \mod n, $$
because $ de \equiv 1 \mod \Phi\br{n} $ and $ x^{\Phi\br{n}} \equiv 1 \mod n $. So if someone wants to send you a message $ c \in \ZZ / n\ZZ $, they compute $ c^e \in \ZZ / n\ZZ $, and send it to you. To decode it, you compute
$$ \br{c^e}^d \equiv c^{de} \equiv c \mod n. $$
This assumes that $ \br{c, n} = 1 $, but the probability of this is extremely high. The prevailing assumption is that with only the information $ n $ and $ e $, it is hopeless to discover $ d $, or to find any other way of recovering $ c $ from $ c^e $.
\lecture{9}{Wednesday}{24/10/18}
Lecture 9 is a problems class.
\subsection{Signing with RSA}
\lecture{10}{Friday}{26/10/18}
If you have functions $ f, g : \ZZ / n\ZZ \to \ZZ / n\ZZ $ with $ f \circ g = g \circ f = \id $, then you can also verify your identity, that is sign messages. Again, make $ f $ public, and any time you publish a message $ m $, you also publish $ g\br{m} $. Then anyone can apply $ f $ to $ g\br{m} $ to recover $ m = f\br{g\br{m}} $, but without $ g $, no one can forge your signature.
\subsection{Discrete logarithms}
Suppose that $ n $ is prime, or more generally that $ \unit{n} $ is cyclic. Let $ g $ be a generator for this group, that is a primitive root. For any $ a \in \unit{n} $, we can write $ a = g^m $ for some unique $ 0 \le m < \Phi\br{n} $. We call $ m $ the \textbf{discrete logarithm} of $ a $ to base $ g $, and write $ m = \log_g\br{a} $.
\begin{example*}
If you want to solve
$$ x^r \equiv a \mod n, $$
write $ x = g^y $, and the congruence becomes equivalent to
$$ yr \equiv \log_g\br{a} \mod \Phi\br{n}. $$
\end{example*}
Unfortunately, or fortunately for cryptography, computing $ \log_g $ is believed to be a hard problem. In particular, there is no known polynomial time algorithm.
\begin{example*}
Imagine that you have a system where you need to store passwords for different users, but you do not want to store the actual passwords. One way to do this is to choose a large prime $ p $ and a primitive root $ g $, and if someone inputs $ x $ as their password, you store $ g^x \mod p $. If they later input $ y $, you compute $ g^y $, and check it matches what you stored. If it does then $ y \equiv x \mod p - 1 $.
\end{example*}
\pagebreak
\section{Quadratic reciprocity}
\subsection{Quadratic residues}
Let $ p $ be a prime number.
\begin{definition}
If $ \br{a, p} = 1 $, then $ a $ is a \textbf{quadratic residue (QR)} if and only if there is a solution to $ x^2 \equiv a \mod p $. If $ \br{a, p} = 1 $ and is not a QR, it is called a \textbf{quadratic non-residue (QNR)}.
\end{definition}
\begin{example*}
\hfill
\begin{itemize}
\item If $ p = 2 $, $ 1 $ is a QR.
\item If $ p = 3 $, $ 1 $ is a QR, and $ -1 $ is a QNR, since $ 1^2 \equiv \br{-1}^2 \equiv 1 \mod 3 $.
\item If $ p = 5 $, $ 1 $ and $ 4 $ are QRs, and $ 2 $ and $ 3 $ are QNRs, since $ 1^2 \equiv 4^2 \equiv 1 \mod 5 $ and $ 2^2 \equiv 3^2 \equiv 4 \mod 5 $.
\end{itemize}
\end{example*}
\begin{lemma}
\label{lem:34}
If $ p > 2 $ then there are exactly $ \br{p - 1} / 2 $ QRs, and $ \br{p - 1} / 2 $ QNRs modulo $ p $.
\end{lemma}
\begin{proof}
The map
$$ \function{\unit{p}}{\unit{p}}{x}{x^2} $$
is a group homomorphism with kernel $ \cbr{\pm 1} $. So the image has order $ \br{p - 1} / 2 $, and the image is exactly the QRs.
\end{proof}
\begin{proposition}
\label{prop:35}
Suppose that $ \br{a, p} = \br{b, p} = 1 $. Then
\begin{itemize}
\item if $ a $ and $ b $ are both QRs, then $ ab $ is a QR,
\item if one of $ a $ and $ b $ is a QR and one is a QNR, then $ ab $ is a QNR, and
\item if $ a $ and $ b $ are both QNRs, then $ ab $ is a QR.
\end{itemize}
\end{proposition}
\begin{proof}
Let $ H $ be the image of
$$ \function{\unit{p}}{\unit{p}}{x}{x^2}, $$
that is $ H $ is the QRs. Then $ \unit{p} / H $ is a group of order two by Lemma \ref{lem:34}, so it is cyclic of order two. This statement is a restatement of Proposition \ref{prop:35}, since $ \unit{p} = H \cup 1 + H $.
\end{proof}
\begin{definition}
Let $ a \in \ZZ $ and $ p $ a prime. Then the \textbf{Legendre symbol} is
$$ \symbol{a}{p} =
\begin{cases}
1 & a \ \text{is a QR modulo} \ p \\
0 & p \mid a \\
-1 & a \ \text{is a QNR modulo} \ p
\end{cases}.
$$
\end{definition}
Proposition \ref{prop:35} can be restated as saying that
$$ \function{\unit{p}}{\cbr{\pm 1}}{a}{\symbol{a}{p}} $$
is a group homomorphism, that is
$$ \symbol{ab}{p} = \symbol{a}{p}\symbol{a}{p}. $$
Even holds if we do not assume that $ \br{a, p} = \br{b, p} = 1 $.
\lecture{11}{Tuesday}{30/10/18}
\begin{theorem}[Euler's criterion]
If $ p $ is an odd prime, and $ p \nmid a $, then
$$ \symbol{a}{p} \equiv a^{\tfrac{p - 1}{2}} \mod p. $$
\end{theorem}
\pagebreak
\begin{proof}
Let $ g $ be a primitive root modulo $ p $, and write $ a \equiv g^r \mod p $ for $ 0 \le r < p - 1 $. Now $ \br{g^{\br{p - 1} / 2}}^2 = g^{p - 1} \equiv 1 \mod p $. So $ g^{\br{p - 1} / 2} \equiv \pm 1 \mod p $. Since $ g $ is a primitive root, $ g^{\tfrac{p - 1}{2}} \not\equiv 1 \mod p $, so $ g^{\br{p - 1} / 2} \equiv -1 \mod p $. So
$$ a^{\tfrac{p - 1}{2}} \equiv \br{g^r}^{\tfrac{p - 1}{2}} \equiv \br{g^{\tfrac{p - 1}{2}}}^r \equiv \br{-1}^r \mod p. $$
But
\begin{align*}
\symbol{a}{p} = 1 \qquad
& \iff \qquad \exists s \in \ZZ, \ \br{g^s}^2 \equiv a \mod p \\
& \iff \qquad 2s \equiv r \mod p - 1 \\
& \iff \qquad r \in 2\ZZ \\
& \iff \qquad \br{-1}^r \equiv 1 \mod p.
\end{align*}
\end{proof}
\subsection{Computing Legendre symbols}
\begin{proposition}
$ -1 $ is a square modulo $ p $ if and only if $ p = 2 $ or $ p \equiv 1 \mod 4 $.
\end{proposition}
\begin{proof}
$ p = 2 $ is trivial. If $ p > 2 $, then by Euler's criterion,
$$ \symbol{-1}{p} \equiv \br{-1}^{\tfrac{p - 1}{2}} \mod p, $$
so in fact
$$ \symbol{-1}{p} = \br{-1}^{\tfrac{p - 1}{2}}. $$
Then
$$ \br{-1}^{\tfrac{p - 1}{2}} =
\begin{cases}
1 & p \equiv 1 \mod 4 \\
-1 & p \equiv 3 \mod 4
\end{cases}.
$$
\end{proof}
\begin{proposition}[Gauss' lemma]
$$ \symbol{2}{p} =
\begin{cases}
1 & p \equiv \pm 1 \mod 8 \\
-1 & p \equiv \pm 3 \mod 8
\end{cases},
$$
that is
$$ \symbol{2}{p} = \br{-1}^{\tfrac{p^2 - 1}{8}}. $$
\end{proposition}
\begin{proof}
$$ \symbol{2}{p} \equiv 2^{\tfrac{p - 1}{2}} \mod p, $$
by Euler's criterion. Let $ q = \br{p - 1} / 2 $, and let
$$ Q = \br{2}\br{4} \dots \br{p - 3}\br{p - 1} = \br{2\br{1}} \dots \br{2\br{q}} = 2^qq! = 2^{\tfrac{p - 1}{2}}q!. $$
Subtracting $ p $ from every term which is bigger than $ q $,
$$ Q \equiv \br{2}\br{4} \dots \br{-3}\br{-1} \equiv \br{-1}^rq! \mod p, $$
where $ r $ is the number of odd integers in $ 1, \dots, q $. Since $ p \nmid q! $, we have $ 2^{\br{p - 1} / 2} \equiv \br{-1}^r \mod p $. Now the following holds. \footnote{Exercise}
$$ \br{-1}^r =
\begin{cases}
1 & p \equiv \pm 1 \mod 8 \\
-1 & p \equiv \pm 3 \mod 8
\end{cases}.
$$
\end{proof}
\pagebreak
\begin{example*}
If $ p \equiv 1 \mod 8 $, say $ p = 1 + 8n $, then $ q = 4n $. Odd integers in $ 1, \dots, 4n $ are $ 1, 3, \dots, 4n - 3, 4n - 1 $, so $ r = 2n $.
\end{example*}
\begin{example*}
\hfill
\begin{itemize}
\item $ \symbol{2}{7} = 1 $, since $ 2 \equiv 3^2 \mod 7 $.
\item $ \symbol{2}{11} = -1 $, since squares modulo $ 11 $ are $ 1, 4, 9, 5, 3 $.
\item $ \symbol{-1}{11} = -1 $, so $ \symbol{-2}{11} = \symbol{2}{11}\symbol{-1}{11} = \br{-1}^2 = 1 $, since $ -2 \equiv 3^2 \mod 11 $.
\end{itemize}
\end{example*}
\begin{theorem}[Law of quadratic reciprocity]
\label{thm:40}
If $ p $ and $ q $ are odd primes, then
$$ \symbol{p}{q} = \symbol{q}{p}\br{-1}^{\br{\tfrac{p - 1}{2}}\br{\tfrac{q - 1}{2}}}, $$
that is $ \symbol{p}{q} = \symbol{q}{p} $ unless $ p \equiv q \equiv 3 \mod 4 $, when $ \symbol{p}{q} = -\symbol{q}{p} $.
\end{theorem}
\begin{example*}
\hfill
\begin{itemize}
\item $ \symbol{5}{p} = \symbol{p}{5} $ for $ p \ne 5 $. QRs modulo $ 5 $ are $ 1 $ and $ 4 $. So
$$ \symbol{5}{p} =
\begin{cases}
1 & p \equiv \pm 1 \mod 5 \\
-1 & p \equiv \pm 2 \mod 5
\end{cases}.
$$
\item What is $ \symbol{3}{p} $ for $ p \ne 3 $? If $ p \equiv 1 \mod 4 $, then
$$ \symbol{3}{p} = \symbol{p}{3} =
\begin{cases}
1 & p \equiv 1 \mod 3 \\
-1 & p \equiv -1 \mod 3
\end{cases}.
$$
If $ p \equiv -1 \mod 4 $, then
$$ \symbol{3}{p} = -\symbol{p}{3} =
\begin{cases}
1 & p \equiv -1 \mod 3 \\
-1 & p \equiv 1 \mod 3
\end{cases}.
$$
So
$$ \symbol{3}{p} =
\begin{cases}
1 & p \equiv \pm 1 \mod 12 \\
-1 & p \equiv \pm 5 \mod 12
\end{cases}.
$$
For example, $ \symbol{3}{7} = -1 $, since QRs are $ 1, 2, 4 $, and $ \symbol{3}{11} = 1 $, since $ 5^2 \equiv 3 \mod 11 $.
\item $ \symbol{6}{19} = \symbol{2}{19}\symbol{3}{19} = \br{-1}\br{-1} = 1 $, since $ \symbol{2}{19} = -1 $, because $ 19 \equiv 3 \mod 8 $, and $ \symbol{3}{19} \equiv -1 \mod 12 $, by the above.
\end{itemize}
\end{example*}
In general to compute $ \symbol{a}{p} $, we could do the following. Use that if $ a \equiv b \mod p $ then $ \symbol{a}{p} = \symbol{b}{p} $. So without loss of generality $ \abs{a} < p $. Then write $ a = \pm\prod_i q_i^{s_i} $ for $ q_i $ prime. Then
$$ \symbol{a}{p} = \symbol{\pm 1}{p} \prod_i \symbol{q_i}{p}^{s_i}. $$
If $ s_i $ is even, then $ \symbol{q_i}{p}^{s_i} = 1 $. If $ s_i $ is odd, then $ \symbol{q_i}{p}^{s_i} = \symbol{q_i}{p} $. We have formulas for $ \symbol{-1}{p} $ and $ \symbol{2}{p} $. If $ q $ is an odd prime, $ q < p $, then use quadratic reciprocity to relate $ \symbol{q}{p} $ and $ \symbol{p}{q} $. Then repeat modulo $ q $.
\pagebreak
\subsection{Proof of quadratic reciprocity}
\lecture{12}{Wednesday}{31/10/18}
The proof of this is due to Rousseau, in 1991. This resembles the proof we gave that $ \symbol{2}{p} = \br{-1}^{\br{p^2 - 1} / 8} $.
\begin{theorem}[Wilson's theorem]
If $ p $ is prime, then $ \br{p - 1}! \equiv -1 \mod p $.
\end{theorem}
\begin{proof}[Proof of Theorem \ref{thm:40}]
We will write down several choices of coset representatives for $ \cbr{\pm 1} $, and compare them, that is we will write down choices of $ x $ or $ -x $ for each $ x \in \unit{pq} $. Write elements of $ \unit{pq} $ as pairs $ \br{\alpha, \beta} \in \unit{p} \times \unit{q} $.
\begin{itemize}
\item For our first set of coset representatives, take
$$ \cbr{\br{x, y} \st 1 \le x \le \tfrac{p - 1}{2}, \ 1 \le y \le q - 1}. $$
Let $ A $ be the product of these coset representatives. This is by definition
$$ A = \br{\br{\br{\tfrac{p - 1}{2}}!}^{q - 1}, \br{-1}^{\tfrac{p - 1}{2}}}. $$
\item The second set of representatives is
$$ \cbr{\br{x, y} \st 1 \le x \le p - 1, \ 1 \le y \le \tfrac{q - 1}{2}}. $$
Let $ B $ be the product of these representatives. Then by symmetry,
$$ B = \br{\br{-1}^{\tfrac{q - 1}{2}}, \br{\br{\tfrac{q - 1}{2}}!}^{p - 1}}. $$
\item For the third set of representatives, select the pairs $ \br{x, y} $ which correspond via the Chinese remainder theorem to the set
$$ \cbr{1 \le i \le \tfrac{pq - 1}{2} \st \br{i, pq} = 1}. $$
Let $ C $ be the product of these coset representatives. What is the $ x $-coordinate of $ C $? It is
$$ \prod_{i = 1, \ \br{i, pq} = 1}^{\tfrac{pq - 1}{2}} i. $$
So
\begin{equation}
\label{eq:1}
\prod_{i = 1, \ \br{i, pq} = 1}^{\tfrac{pq - 1}{2}} i = \br{\prod_{i = 1, \ \br{i, p} = 1}^{\tfrac{pq - 1}{2}} i} \ \Bigg/ \ \br{\prod_{i = 1, \ \br{i, p} = 1, \ q \mid i}^{\tfrac{pq - 1}{2}} i},
\end{equation}
\begin{equation}
\label{eq:2}
\prod_{i = 1, \ \br{i, p} = 1}^{\tfrac{pq - 1}{2}} i = \br{\prod_{i = 1, \ \br{i, p} = 1}^{p\br{\tfrac{q - 1}{2}}} i}\br{\prod_{i = p\br{\tfrac{q - 1}{2}} + 1, \ \br{i, p} = 1}^{p\br{\tfrac{q - 1}{2}} + \tfrac{p - 1}{2}} i},
\end{equation}
\begin{equation}
\label{eq:3}
\prod_{i = 1, \ \br{i, p} = 1, \ q \mid i}^{\tfrac{pq - 1}{2}} i = \prod_{j = 1, \ \br{j, p} = 1}^{\tfrac{p - 1}{2}} qj = q^{\tfrac{p - 1}{2}}\br{\tfrac{p - 1}{2}}!.
\end{equation}
Combining $ \br{\ref{eq:1}}, \br{\ref{eq:2}}, \br{\ref{eq:3}} $, get that the $ x $-coordinate of the product is
$$ \prod_{i = 1, \ \br{i, pq} = 1}^{\tfrac{pq - 1}{2}} i = \dfrac{\br{p - 1}!^{\tfrac{q - 1}{2}}\br{\tfrac{p - 1}{2}}!}{q^{\tfrac{p - 1}{2}}\br{\tfrac{p - 1}{2}}!} = \dfrac{\br{-1}^{\tfrac{q - 1}{2}}}{q^{\tfrac{p - 1}{2}}}. $$
So $ C $, the product of these representatives, is
$$ C = \br{\br{-1}^{\tfrac{q - 1}{2}}\symbol{q}{p}, \br{-1}^{\tfrac{p - 1}{2}}\symbol{p}{q}}. $$
\end{itemize}
\pagebreak