euler_trinomial_strong_psp.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/perl
  2. # CYF NO. 54: Find the smallest positive integer n such that Eulers Trinomial n*n + n + 41 gives a Strong Pseudoprime (base-2).
  3. # https://shyamsundergupta.com/canyoufind.htm
  4. # As far as I know, no such numbers are known.
  5. # Not even a regular base-2 pseudoprime of this form is known.
  6. use 5.020;
  7. use strict;
  8. use warnings;
  9. use Math::GMPz;
  10. use ntheory qw(:all);
  11. use Math::Prime::Util::GMP;
  12. use Math::Sidef qw(iquadratic_formula);
  13. my %seen;
  14. my $z = Math::GMPz::Rmpz_init();
  15. my $t = Math::GMPz::Rmpz_init();
  16. while (<>) {
  17. next if /^\h*#/;
  18. /\S/ or next;
  19. my $n = (split(' ', $_))[-1];
  20. $n > ~0 or next;
  21. $n || next;
  22. # Check if `4*(n-41) + 1` is a square
  23. Math::GMPz::Rmpz_set_str($t, "$n", 10);
  24. Math::GMPz::Rmpz_sub_ui($t, $t, 41);
  25. Math::GMPz::Rmpz_mul_2exp($t, $t, 2);
  26. Math::GMPz::Rmpz_add_ui($t, $t, 1);
  27. Math::GMPz::Rmpz_perfect_square_p($t) || next;
  28. say "Passes the square test: $n";
  29. Math::Prime::Util::GMP::is_pseudoprime($n, 2) || next;
  30. #Math::Prime::Util::GMP::is_strong_pseudoprime($n, 2) || next;
  31. Math::GMPz::Rmpz_set_str($z, "$n", 10);
  32. my @solutions = iquadratic_formula(-1, -1, $z - 41);
  33. my $x = $solutions[-1];
  34. say "Testing: $n with x = $x";
  35. if ($x * $x + $x + 41 == $z) {
  36. die ":: Found: $n with x = $x";
  37. }
  38. }
  39. __END__
  40. # Some other data:
  41. 1388903 with n = 1178 (Fibonacci pseudoprime)
  42. 4090547 with n = 2022 (Pell pseudoprime)
  43. 65682961 with n = 8104 (base-3 pseudoprime)
  44. 6778640597 with n = 82332 (base-4 pseudoprime)
  45. 16297 with n = 127 (base-5 pseudoprime)
  46. 601441 with n = 775 (base-6 pseudoprime)
  47. 296717891 with n = 17225 (base-7 pseudoprime)
  48. 510153776791 with n = 714250 (base-11 pseudoprime)
  49. 54097 with n = 232 (base-13 pseudoprime)
  50. 601441 with n = 775 (base-14 pseudoprime)
  51. 6877467871 with n = 82930 (base-15 pseudoprime)