fermat_with_n_factors_where_p-1_does_not_divide_k-1.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/perl
  2. # a(n) is the smallest k with n prime factors such that 2^(k-1) == 1 (mod k) and p-1 does not divide k-1 for every prime p dividing k.
  3. # https://oeis.org/A316908
  4. # Known terms:
  5. # 7957, 617093, 134564501, 384266404601, 8748670222601, 6105991025919737, 901196605940857381
  6. use 5.020;
  7. use strict;
  8. use warnings;
  9. use ntheory qw(:all);
  10. use Math::GMPz;
  11. use Math::AnyNum qw(is_smooth);
  12. my %seen;
  13. my %table;
  14. while (<>) {
  15. next if /^\h*#/;
  16. /\S/ or next;
  17. my $n = (split(' ', $_))[-1];
  18. $n || next;
  19. next if (length($n) > 40);
  20. is_pseudoprime($n, 2) || next;
  21. is_smooth($n, 1e5) || next;
  22. if ($n > ((~0) >> 1)) {
  23. $n = Math::GMPz->new("$n");
  24. }
  25. my @f = factor($n);
  26. my $t = $n - 1;
  27. my $key = scalar(@f);
  28. if (exists $table{$key}) {
  29. next if ($n >= $table{$key});
  30. }
  31. if (vecany { $t % ($_ - 1) == 0 } @f) {
  32. next;
  33. }
  34. if ($key >= 9) {
  35. say "a($key) <= $n";
  36. }
  37. if (exists $table{$key}) {
  38. if ($n < $table{$key}) {
  39. $table{$key} = $n;
  40. }
  41. }
  42. else {
  43. $table{$key} = $n;
  44. }
  45. }
  46. say '';
  47. foreach my $n (sort { $a <=> $b } keys %table) {
  48. say "a($n) <= $table{$n}";
  49. }
  50. __END__
  51. a(2) = 7957
  52. a(3) = 617093
  53. a(4) = 134564501
  54. a(5) = 384266404601
  55. a(6) = 8748670222601
  56. a(7) = 6105991025919737
  57. a(8) = 901196605940857381
  58. # New upper-bounds:
  59. a(9) <= 797365221484475174021
  60. a(10) <= 1315856103949347820015303981
  61. a(11) <= 6357507186189933506573017225316941
  62. a(12) <= 77822245466150976053960303855104674781
  63. a(13) <= 42864570625001423761497389323695509974049581
  64. a(14) <= 34015651529746754841597629769101132590516759547941
  65. a(15) <= 53986954871543199290951271756765558658193549930487667861
  66. # Old upper-bounds:
  67. a(9) <= 521957994426556057126261
  68. a(9) <= 35092334596330107098253061
  69. a(9) <= 519733504158090289696355563896841
  70. a(9) <= 3929067709870830008475826012909048255937
  71. a(10) <= 520194865399874183191033279741
  72. a(11) <= 6367705347359859876441438377309581