nine_nine_nine_pseudoprimes.pl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/perl
  2. # Find new Fibonacci / Lucas pseudoprimes, by appending a run of 9's at the end of other pseudoprimes.
  3. # Curious example:
  4. # 430479503 # is a Fibonacci/Lucas pseudoprime
  5. # 43047950399 # is a Fibonacci/Lucas pseudoprime
  6. # 4304795039999 # is a Pell pseudoprime
  7. # Also:
  8. # 430479503 = 20747 * 20749
  9. # 43047950399 = 207479 * 207481
  10. # 4304795039999 = 2074799 * 2074801
  11. use 5.020;
  12. use strict;
  13. use warnings;
  14. use experimental qw(signatures);
  15. use Math::GMPz;
  16. use Math::Prime::Util::GMP qw(is_prob_prime is_pseudoprime is_lucas_pseudoprime is_extra_strong_lucas_pseudoprime is_almost_extra_strong_lucas_pseudoprime);
  17. sub is_fibonacci_pseudoprime ($n) {
  18. Math::Prime::Util::GMP::lucasumod(1, -1, Math::Prime::Util::GMP::subint($n, kronecker($n, 5)), $n) eq '0';
  19. }
  20. sub is_lucas_carmichael ($n) {
  21. my $t = Math::GMPz->new($n) + 1;
  22. vecall { $t % ($_ + 1) == 0 } factor($n);
  23. }
  24. while (<>) {
  25. next if /^\h*#/;
  26. /\S/ or next;
  27. my $n = (split(' ', $_))[-1];
  28. #next if ($n <= 6479);
  29. #next if ($n > ((~0)>>1));
  30. #<<<
  31. #~ while (substr($n, -1) eq '9') {
  32. #~ chop $n;
  33. #~ $n eq '' and last;
  34. #~ (substr($n, -1) & 1) || last;
  35. #~ is_prob_prime($n) && next;
  36. #~ if (is_lucas_pseudoprime($n)) {
  37. #~ say $n;
  38. #~ }
  39. #~ elsif (is_fibonacci_pseudoprime($n)) {
  40. #~ say $n;
  41. #~ }
  42. #~ }
  43. #>>>
  44. next if length($n) > 100;
  45. is_pseudoprime($n, 2) && next;
  46. if ( is_lucas_pseudoprime($n)
  47. or is_extra_strong_lucas_pseudoprime($n)
  48. or is_almost_extra_strong_lucas_pseudoprime($n)) {
  49. #if (1) {
  50. foreach my $k (1 .. 9) {
  51. my $t = $n . ('9' x $k);
  52. is_prob_prime($t) && next;
  53. if ( is_lucas_pseudoprime($t)
  54. or is_extra_strong_lucas_pseudoprime($t)
  55. or is_almost_extra_strong_lucas_pseudoprime($t)) {
  56. say $t;
  57. }
  58. #elsif (is_fibonacci_pseudoprime($t)) {
  59. # say $t;
  60. #}
  61. }
  62. }
  63. }