largest_ndigit_pseudoprime_cached.pl 705 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/perl
  2. # a(n) is the largest n-digit pseudoprime (to base 2).
  3. # https://oeis.org/A067845
  4. use 5.020;
  5. use strict;
  6. use warnings;
  7. use Storable;
  8. use Math::GMPz;
  9. use ntheory qw(:all);
  10. use Math::Prime::Util::GMP;
  11. use experimental qw(signatures);
  12. my $storable_file = "cache/factors-fermat.storable";
  13. my $fermat = retrieve($storable_file);
  14. my %table;
  15. foreach my $n (sort { $b <=> $a } map { Math::GMPz->new($_) } keys %$fermat) {
  16. my $len = length("$n");
  17. next if $len > 100;
  18. next if (exists $table{$len});
  19. $table{$len} //= $n;
  20. if ($n > $table{$len}) {
  21. $table{$len} = $n;
  22. }
  23. }
  24. foreach my $len (sort { $a <=> $b } keys %table) {
  25. say "$len $table{$len}";
  26. }