generate.pl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/perl
  2. # Lexicographically earliest sequence of prime numbers whose partial products, starting from the second, are all Fermat pseudoprimes to base 2 (A001567).
  3. # https://oeis.org/A374028
  4. # First few terms:
  5. # 11, 31, 41, 61, 181, 54001, 6841, 54721, 110017981, 13681, 20521, 61561, 123121, 225721, 246241, 205201, 410401, 1128601, 513001, 3078001, 4617001, 73442619001, 96993612810001, 55404001, 7188669001, 16773561001, 67094244001, 821904489001, 29370505311001
  6. use 5.036;
  7. use ntheory qw(:all);
  8. use Math::Prime::Util::GMP;
  9. use Math::GMPz;
  10. # PARI/GP program:
  11. # my(P=List(11), base=2); my(m = vecprod(Vec(P))); my(L = znorder(Mod(base, m))); print1(P[1], ", "); while(1, forstep(p=lift(1/Mod(m, L)), oo, L, if(isprime(p) && m % p != 0 && base % p != 0, if((m*p-1) % znorder(Mod(base, p)) == 0, print1(p, ", "); listput(P, p); L = lcm(L, znorder(Mod(base, p))); m *= p; break))));
  12. my @primes = (11);
  13. my $base = 2;
  14. my $m = Math::GMPz->new(vecprod(@primes));
  15. my $L = Math::GMPz->new(znorder($base, $m));
  16. while (1) {
  17. my $u = Math::GMPz::Rmpz_init();
  18. my $v = Math::GMPz::Rmpz_init();
  19. my $t = Math::GMPz::Rmpz_init();
  20. Math::GMPz::Rmpz_invert($v, $m, $L);
  21. for (my $p = $v ; ; Math::GMPz::Rmpz_add($p, $p, $L)) {
  22. if (Math::GMPz::Rmpz_probab_prime_p($p, 5) && !Math::GMPz::Rmpz_divisible_p($m, $p)) {
  23. Math::GMPz::Rmpz_mul($u, $m, $p);
  24. Math::GMPz::Rmpz_sub_ui($u, $u, 1);
  25. Math::GMPz::Rmpz_set_str($t, Math::Prime::Util::GMP::znorder($base, $p), 10);
  26. if (Math::GMPz::Rmpz_divisible_p($u, $t)) {
  27. say $p;
  28. push @primes, Math::GMPz::Rmpz_init_set($p);
  29. $L = Math::GMPz->new(lcm($L, $t));
  30. $m *= $p;
  31. last;
  32. }
  33. }
  34. }
  35. }
  36. __END__
  37. 31
  38. 41
  39. 61
  40. 181
  41. 54001
  42. 6841
  43. 54721
  44. 110017981
  45. 13681
  46. 20521
  47. 61561
  48. 123121
  49. 225721
  50. 246241
  51. 205201
  52. 410401
  53. 1128601
  54. 513001
  55. 3078001
  56. 4617001
  57. 73442619001
  58. 96993612810001
  59. 55404001
  60. 7188669001
  61. 16773561001
  62. 67094244001
  63. 821904489001
  64. 29370505311001
  65. 91281718962001
  66. 18014804514001
  67. 45037011285001
  68. 225185056425001
  69. 10358512595550001
  70. 56971819275525001
  71. 145019176337700001
  72. 217528764506550001
  73. 870115058026200001
  74. 1160153410701600001
  75. 6815901287871900001
  76. 68159012878719000001
  77. 112980379747764614400001
  78. 245426973573691375200001