Kiem tra Fermat la mot thuat toan xac suat kiem tra mot so tu nhien la hop so hay la so nguyen to.


Khai niem Đinh ly nho Fermat phat bieu rang neu p la so nguyen to va 
  
    
      
        1
        ≤
        a
        <
        p
      
    
    {\displaystyle 1\leq a<p}
  
, thi

  
    
      
        
          a
          
            p
            −
            1
          
        
        ≡
        1
        
          
          (
          mod
          
          p
          )
        
      
    
    {\displaystyle a^{p-1}\equiv 1{\pmod {p}}}
  
.
Neu ta muon kiem tra so n co la nguyen to khong, ta lay ngau nhien cac so a' va kiem tra xem đang thuc tren co đung khong. Neu no khong đung voi mot gia tri a nao đo thi n la hop so. Neu đang thuc đung voi nhieu gia tri cua a, ta co the noi rang n la so nguyen to voi xac suat nao đo, hay la mot so gia nguyen to (pseudoprime).
Co the phep thu se cho ta mot ket qua sai.
So a ma

  
    
      
        
          a
          
            n
            −
            1
          
        
        ≡
        1
        
          
          (
          mod
          
          n
          )
        
      
    
    {\displaystyle a^{n-1}\equiv 1{\pmod {n}}}
  

trong khi n la hop so đuoc goi la mot gia Fermat.
Con neu co so a ma

  
    
      
        
          a
          
            n
            −
            1
          
        
        ≡
        1
        
          
          (
          mod
          
          n
          )
        
      
    
    {\displaystyle a^{n-1}\not \equiv 1{\pmod {n}}}
  

thi a đuoc xem nhu mot bang chung Fermat chung to n la hop so.


Thuat toan va thoi gian thi hanh Thuat toan co the viet nhu sau:

Inputs: n: gia tri đe kiem tra tinh nguyen to; k: tham so tham gia vao qua trinh kiem tra
Output: hop so neu n la hop so, neu khong nguyen to xac suat
repeat k times:
lay a ngau nhien trong [1, n − 1]
if an − 1 mod n = 1 then
return composite
return probably prime
Khi dung thuat toan tinh nhanh luy thua theo mođun, thoi gian thi hanh cua thuat toan la O(k × log3n), o đo k la so lan kiem tra voi moi so a ngau nhien, va n la gia tri ta muon kiem tra.


Kha nang van dung Co kha nhieu gia tri cua n la cac so Carmichael ma voi tat ca  cac gia tri cua a sao cho UCLN(a,n)=1 la gia Fermat. Mac du cac so Carmichael la rat hiem, nhung phep thu Fermat rat it đuoc dung so voi cac phuong phap khac nhu kiem tra Miller-Rabin hay kiem tra Solovay-Strassen.
Noi chung, neu n khong la so Carmichael thi it nhat mot nua cac so

  
    
      
        a
        ∈
        (
        
          Z
        
        
          /
        
        n
        
          Z
        
        
          )
          
            ∗
          
        
      
    
    {\displaystyle a\in (\mathbb {Z} /n\mathbb {Z} )^{*}}
  

la bang chung Fermat. Đe chung minh đieu nay, gia su a la mot bang chung Fermat va a1, a2,..., as la gia Fermat. Khi đo

  
    
      
        (
        a
        ⋅
        
          a
          
            i
          
        
        
          )
          
            n
            −
            1
          
        
        ≡
        
          a
          
            n
            −
            1
          
        
        ⋅
        
          a
          
            i
          
          
            n
            −
            1
          
        
        ≡
        
          a
          
            n
            −
            1
          
        
        ≡
        1
        
          
          (
          mod
          
          n
          )
        
      
    
    {\displaystyle (a\cdot a_{i})^{n-1}\equiv a^{n-1}\cdot a_{i}^{n-1}\equiv a^{n-1}\not \equiv 1{\pmod {n}}}
  

va do đo tat ca a × ai for i = 1, 2,..., s la bang chung Fermat.


Xem them Kiem tra tinh nguyen to
RSA (ma hoa)
Pretty Good Privacy
Pierre de Fermat


Chu thich Tham khao