prog.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/perl
  2. # a(n) is the smallest prime p such that 2^(p-1) == 1 (mod a(0)*...*a(n-1)*p), with a(0) = 1.
  3. # https://oeis.org/A175257
  4. # Daniel Suteu: p-1 seems to be very smooth. Based on this observation, I conjecture that the next few terms, after a(26), are:
  5. # 481461926401, 722192889601, 2888771558401, 7944121785601, 55608852499201, 111217704998401, 889741639987201, 1779483279974401, 3114095739955201.
  6. # a(27) = 481461926401 was confirmed by Hans Havermann (Mar 29 2019).
  7. use 5.020;
  8. use warnings;
  9. use experimental qw(signatures);
  10. use Math::GMPz;
  11. use ntheory qw(:all);
  12. use Math::AnyNum qw(prod);
  13. sub check_valuation ($n, $p) {
  14. if ($p == 2) {
  15. return valuation($n, $p) < 13;
  16. }
  17. if ($p == 3) {
  18. return valuation($n, $p) < 12;
  19. }
  20. if ($p == 5) {
  21. return valuation($n, $p) < 5;
  22. }
  23. if ($p == 7) {
  24. return valuation($n, $p) < 5;
  25. }
  26. if ($p == 11) {
  27. return valuation($n, $p) < 3;
  28. }
  29. if ($p == 13) {
  30. return valuation($n, $p) < 5;
  31. }
  32. if ($p == 17) {
  33. return valuation($n, $p) < 3;
  34. }
  35. ($n % $p) != 0;
  36. }
  37. sub smooth_numbers ($limit, $primes) {
  38. my @h = (1);
  39. foreach my $p (@$primes) {
  40. say "Prime: $p";
  41. foreach my $n (@h) {
  42. if ($n * $p <= $limit) { #and check_valuation($n, $p)) {
  43. push @h, $n * $p;
  44. }
  45. }
  46. }
  47. return \@h;
  48. }
  49. my $mod = prod(3, 5, 13, 37, 73, 109, 181, 541, 1621, 4861, 9721, 19441, 58321, 87481, 379081, 408241, 2041201, 2449441, 7348321, 14696641, 22044961, 95528161, 382112641, 2292675841, 8024365441, 40121827201, 481461926401, 722192889601, 2888771558401, 7944121785601, 55608852499201, 111217704998401, 889741639987201, 1779483279974401, 3114095739955201);
  50. sub isok ($n) {
  51. if (is_prime($n+1)) {
  52. return powmod(2, $n, ($n+1)*$mod) == 1
  53. }
  54. return 0;
  55. }
  56. # 481461926401
  57. my $h = smooth_numbers(3114095739955201, primes(23));
  58. say "\nFound: ", scalar(@$h), " terms";
  59. my @list;
  60. foreach my $n (@$h) {
  61. my $p = isok($n);
  62. if ($p) {
  63. say "a($p) = ", $n+1, " -> ", join(' * ', map { "$_->[0]^$_->[1]" } factor_exp($n));
  64. push @list, $n+1;
  65. }
  66. }
  67. say vecmin(@list);