pomerance_smooth_primes_cached.pl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/perl
  2. # Extract primes from Carmichael numbers that satisfy Pomerance's conditions for being a factor a PSW pseudoprime.
  3. use 5.020;
  4. use strict;
  5. use warnings;
  6. use Storable;
  7. use ntheory qw(:all);
  8. use Math::Prime::Util::GMP;
  9. use experimental qw(signatures);
  10. #my $storable_file = "cache/factors-carmichael.storable";
  11. my $storable_file = "cache/factors-lucas-carmichael.storable";
  12. my $carmichael = retrieve($storable_file);
  13. my $B = 100_000; # smooth value
  14. my %seen;
  15. while (my ($n, $value) = each %$carmichael) {
  16. foreach my $p (split(' ', $value)) {
  17. length($p) < 100 or next;
  18. modint($p, 8) == 3 or next;
  19. kronecker(5, $p) == -1 or next;
  20. next if exists $seen{$p};
  21. undef $seen{$p};
  22. # Conditions for p +/- 1
  23. my $pp1 = addint($p, 1);
  24. my $pm1 = subint($p, 1);
  25. modint($pp1, 4) == 0 or next;
  26. modint($pp1, 8) != 0 or next;
  27. modint($pm1, 4) != 0 or next;
  28. my $pm1d2 = divint($pm1, 2);
  29. my $pp1d4 = divint($pp1, 4);
  30. modint($pm1d2, 4) == 1 or next;
  31. is_smooth($pp1d4, $B) or next;
  32. is_smooth($pm1d2, $B) or next;
  33. #is_square_free($pp1d4) or next;
  34. #is_square_free($pm1d2) or next;
  35. next if not vecall { modint($_, 4) == 3 } factor($pp1d4);
  36. next if not vecall { modint($_, 4) == 1 } factor($pm1d2);
  37. say $p;
  38. }
  39. }