fork download
  1. def lucas_lehmer_test(p):
  2. # s = 4
  3. # repetăm de (p-2) ori:
  4. # s = (s^2 - 2) mod (2^p - 1)
  5.  
  6. s = 4
  7. M_p = (2**p) - 1
  8.  
  9. for i in range(p - 2):
  10. # AICI este punctul critic! s*s este o înmulțire de numere gigantice.
  11. # Trebuie să folosim FFT pentru a calcula s^2.
  12. s = (s * s - 2) % M_p
  13.  
  14. if s == 0:
  15. return "PRIM GĂSIT! (150.000$ sunt ai tăi)"
  16. else:
  17. return "Compus"
Success #stdin #stdout 0.07s 14216KB
stdin
Standard input is empty
stdout
Standard output is empty