X =y (modp) M5i sd bit ky ludn tUOng duong modul op vdi mot
Dinh ly 5.3.4 (Dinh ly Fermat nho)
Neu p Id nguyen to va o £ Z j thi â"^ = 1 (modp). • Thi du, neu p = 7 va a = 2, dinh ly nay ndi r^ng 2(^-1) mod 7 se
la 1 bdi v i 7 la nguyen tọ Dieu nay duoc xac lap bdi tinh toan don gian nhu sau:
318 Cac giai phap Gia thijt r^ng t a thay p = 6. K h i do
2^^-^) = 2^ = 32 va 32 mod 6 = 2
cho t a ket qua khac 1, theo Dinh ly Fermat nho, ham y rang 6 khong la nguyen tọ Tat nhien, dieu ay t a da biet roị Tuy vay, phuong phap nay chi ra rang 6 la hap so ma khong can phai t i m nhan tijf cua nọ Chilng minh Dinh ly Fermat nho tirong d6i dan gian va diiac t r i n h bay trong nhieu tai lieu ve ly thuygt sọ
Dinh l y Fermat nho gai nen mot kigu " t h t f ' doi vdi t m h
nguyen to, dildc goi la phep thvC Fermat {Fermat test). K h i t a
noi v^ng p qua duac phep thiJt Fermat vdi a, dieu do c6 nghia la
Q C P - I ) = 1 (modp). N h u vay, Dinh ly Fermat nho noi rang moi so
nguyen to p deu qua duac t a t ca cac phep thiJt Fermat vdi m 5 i a e Z° . N h u da thay rang 6 khong qua duac mot phep t h i i Fermat, nen 6 khong la nguyen tọ
Ligu t a CO the sii dung phep t h i i nay de xay dung thuat toan cho viec xac dinh tinh nguyen tỏ Hau nhu la duac. M o t so duac
goi la ti/a nguyen t S (pseudoprime) n i u no qua duac cac phep
thijt Fermat vdi t a t ca cac so nho han a nguyen to cimg nhau vdi
nọ Vdi ngoai le higm hoi nhu cdc so Carmichael {Carmichael
numbers), tUc la nhUng hap so ma vQn qua duac tat ca cdc phep thii Fermat, va cac so t u a nguyen to dong nhat vdi cac so nguyen tọ
Ta b^t dau bang viec xay dung thuat toan xac suat thdi gian da thiic dan gian dg phan biet cac so nguyen to vdi cac hap so t r i i cac so Carmichael. Sau do, t a de xuat va phan tich thuat toan xac suat hoan chinh kigm t r a tinh nguygn t6. Thuat toan kigm t r a t i n h tua nguygn to can thuc hien t a t ca cac phep t h i i Fermat nen doi hoi thdi gian ham mụ M a u chot cho thuat toan xac suat thdi gin da
thiic la d ch5, neu mot so khong la t u a nguygn to, no khong qua duac I t nhat mot niia so cac phep thiJt (Bai tap 5.13). Thuat toan tign hanh thuc hien mot so phep thijf duoc chon n g l u nhien. Neu khong qua duac mot phep thijt nao, dau vao phai la hap sọ Thuat
toan chUa mOt tham so duar •invg dg xac dinh xac suat sai lech.
5.3 Thuat toan xac sudt 319
^ P S E U D O P R I M E = "Trgn dau vao p :
1. Chon ngau nhign a i , ... ,af. trong Z " . 2. T i n h ẫ^ m o d p doi vdi tiing ị
3. Neu tat ca cac gia t r i t h u duoc deu la 1, chap nhan; ngUdc lai, bac bọ'"
K h i p la nguyen to, no qua duoc t a t ca cac phep thijf va duac thuat toan chap nhan vdi xac suat chac chan. K h i p khong phai la
tua nguygn to, no qua duac nhieu nhat mot niia so cac phep t h i i . Trong trudng hap ay no qua duac tUng phep thijt dugc lua chon n g i u nhign vdi xac suat nhieu nhat la |. Bdi vay, xac suat ma no
qua duac t a t ca k phep t h i i dugc chon n g l u nhien nhieu nhat la
2"'=. Thuat toan tien hanh trong thdi gian da thiic, bdi v i luy thiia modulo la t i n h duac trong thdi gian da thiic (Bai t a p 2.8). Dg sijta
đi thuat toan vita neu thanh thuat toan kiem t r a t i n h nguygn to,
ta dua thgm phep thijt cong phu han, tranh va cham vdi cac so Carmichael. Nguygn ly co ban la: so 1 c6 dUng hai gia t r i can bac hai, 1 va - 1 , modulo nguyen to p bat kỵ D o i vdi nhieu hap so,
bao gom t a t ca cac so Carmichael, 1 c6 bon gia t r i can bac hai hoac nhieu han. T h i du, ± 1 va ± 8 la bon gia t r i can bac hai cua 1,
modulo 21. Ngu m p t so p qua duac phep t h i i Fermat vdi a, thuat
toan t i m duac nglu^-nhign mot trong so cac gia t r i can bac hai cua 1,
modulo p, va xac dinh xem gia t r i ay c6 la 1 hoac - 1 hay khdng. Neu khong phai, t a nhan ra r^ng p khong la nguygn tọ
Ta CO the t h u duac cac gia t r i can bac hai cua 1 neu so p qua duoc
phep thijt Fermat vdi a, bdi v i â"^ modp = 1. Do do a^P-^)/^ ^ ^ ^ ^
la gia t r i can bac hai cua 1. Neu gia t r i can ay v l n la 1 va ket qua chia so m u cho 2 v l n c6n la s6 nguygn, t a tiep tuc chia so m u cho
2 va lap l a i viec chia nay moi khi ca hai yeu cau vHa ngu v l n duoc
dam baọ Ta se chUng m i n h mot each hinh thUc t i n h c h u i n xac cua thuat toan ngay sau khi mo t a nọ Ta chon A; > 1 n h u m o t tham so sao cho xac suat sai lech t o i da la 2 .
320 Cac giai phap
^ P R I M E = "Tren dau vho p:
1. Khi p chan, chap nhan ngu p = 2; ngiroc lai, bdc bọ