almost_carmichael_pseudoprime_cached.pl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/perl
  2. # Smallest weak pseudoprime to all natural bases up to prime(n) that is not a Carmichael number.
  3. # https://oeis.org/A285549
  4. # Version with terms > 2^64.
  5. use 5.020;
  6. use strict;
  7. use warnings;
  8. use Storable;
  9. use Math::GMPz;
  10. use ntheory qw(:all);
  11. use Math::Prime::Util::GMP;
  12. use experimental qw(signatures);
  13. my $fermat_file = "cache/factors-fermat.storable";
  14. my $carmichael_file = "cache/factors-carmichael.storable";
  15. my $carmichael = retrieve($carmichael_file);
  16. my $fermat = retrieve($fermat_file);
  17. my @terms;
  18. while (my ($n) = each %$fermat) {
  19. next if length($n) > 100;
  20. next if exists $carmichael->{$n};
  21. push @terms, Math::GMPz->new($n);
  22. }
  23. @terms = sort { $a <=> $b } @terms;
  24. my $p = 2;
  25. my @bases = ($p);
  26. foreach my $n (@terms) {
  27. while (is_pseudoprime($n, $bases[-1])) {
  28. printf("a(%2d) <= %s\n", scalar(@bases), $n);
  29. $p = next_prime($p);
  30. push @bases, $p;
  31. }
  32. }
  33. __END__
  34. a( 1) <= 18446744073709551617
  35. a( 2) <= 18446752100793694681
  36. a( 3) <= 18446752100793694681
  37. a( 4) <= 18446752100793694681
  38. a( 5) <= 18479446505090544961
  39. a( 6) <= 18785283139452669841
  40. a( 7) <= 18785283139452669841
  41. a( 8) <= 18872942465780679457
  42. a( 9) <= 18872942465780679457
  43. a(10) <= 18872942465780679457
  44. a(11) <= 29782535170930902361
  45. a(12) <= 44212062084973544161
  46. a(13) <= 110098481668555259881
  47. a(14) <= 110098481668555259881
  48. a(15) <= 110098481668555259881
  49. a(16) <= 183404635770837594961
  50. a(17) <= 183404635770837594961
  51. a(18) <= 1543267864443420616877677640751301
  52. a(19) <= 1543267864443420616877677640751301
  53. # Very large term:
  54. a(20) <= 8038374574536394912570796143419421081388376882875581458374889175222974273765333652186502336163960045457915042023603208766569966760987284043965408232928738791850869166857328267761771029389697739470167082304286871099974399765441448453411558724506334092790222752962294149842306881685404326457534018329786111298960644845216191652872597534901