fermat_pseudoprimes_generation.jl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/julia
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 28 August 2020
  4. # https://github.com/trizen
  5. # A new algorithm for generating Fermat super-pseudoprimes to base 2.
  6. # OEIS:
  7. # https://oeis.org/A050217 -- Super-Poulet numbers: Poulet numbers whose divisors d all satisfy d|2^d-2.
  8. # https://oeis.org/A214305 -- Fermat pseudoprimes to base 2 with two prime factors.
  9. # See also:
  10. # https://en.wikipedia.org/wiki/Fermat_pseudoprime
  11. # https://trizenx.blogspot.com/2020/08/pseudoprimes-construction-methods-and.html
  12. using Primes
  13. using Combinatorics
  14. function divisors(n)
  15. d = Int64[1]
  16. for (p,e) in factor(n)
  17. t = Int64[]
  18. r = 1
  19. for i in 1:e
  20. r *= p
  21. for u in d
  22. push!(t, u*r)
  23. end
  24. end
  25. append!(d, t)
  26. end
  27. return d
  28. end
  29. function fermat_pseudoprimess()
  30. table = Dict{Int64, Array{Int64}}()
  31. #@for p in primes(7006770,500040561)
  32. #for p in primes(65521, 230040561)
  33. #for p in primes(70067700,650040561)
  34. for p in primes(3, 7 * 10^8)
  35. ((p % 24) == 1) || ((p % 24) == 13) || continue
  36. #((p % 12) == 1) || ((p % 12) == 7) || continue
  37. #((p % 24) == 1) || continue
  38. #((p % 12) == 1) || continue
  39. for d in (divisors(p-1))
  40. if (powermod(2, d, p) == 1)
  41. if (haskey(table, d))
  42. push!(table[d], p)
  43. else
  44. table[d] = [p]
  45. end
  46. end
  47. end
  48. end
  49. for (k,v) in table
  50. for k in 5:length(v)
  51. for c in combinations(v,k)
  52. println(prod(map(x -> BigInt(x), c)))
  53. end
  54. end
  55. end
  56. return true
  57. end
  58. #fermat_pseudoprimess(10^5)
  59. fermat_pseudoprimess()