upper-bounds.pl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/perl
  2. # The smallest number whose prime factor concatenation, when written in base n, contains all digits 0,1,...,(n-1).
  3. # https://oeis.org/A372309
  4. # Known terms:
  5. # 2, 6, 38, 174, 2866, 11670, 135570, 1335534, 15618090, 155077890, 5148702870
  6. # This program computes upper-bounds.
  7. # New upper-bounds:
  8. # a(14) <= 774841780230
  9. # a(15) <= 11924858870610
  10. # a(16) <= 256023548755170
  11. # a(17) <= 4286558044897590
  12. use 5.036;
  13. use ntheory qw(:all);
  14. use List::Util qw(uniq shuffle);
  15. sub f ($arr, $p, $n, $value, $max_value, $callback) {
  16. if (scalar(@$arr) == $n and $value >= factorial($n)) {
  17. my @D = map { todigits($_, $n) } factor($value);
  18. if (scalar(@D) == $n) {
  19. $callback->($value);
  20. $max_value = $value if ($value < $max_value);
  21. }
  22. return $max_value;
  23. }
  24. my $limit = divint($max_value, $value);
  25. $limit = vecmin($limit, 1e6);
  26. my %arr_lookup;
  27. @arr_lookup{@$arr} = ();
  28. for(; $p <= $limit; $p = next_prime($p)) {
  29. if ($value*$p <= $max_value) {
  30. my @D = todigits($p, $n);
  31. if ((vecnone { exists $arr_lookup{$_} } @D) and join(' ', @D) eq join(' ', uniq(@D))) {
  32. $max_value = f([@$arr, @D], $p, $n, $value * $p, $max_value, $callback);
  33. }
  34. }
  35. }
  36. return $max_value;
  37. }
  38. my $n = 9;
  39. my $max = 2;
  40. #~ $n = 12;
  41. #~ $max = 5148702870;
  42. #~ $n = 13;
  43. #~ $max = 31771759110;
  44. #~ $n = 14;
  45. #~ $max = 774841780230;
  46. #~ $n = 15;
  47. #~ $max = 11924858870610;
  48. #~ $n = 16;
  49. #~ $max = 256023548755170;
  50. #~ $n = 17;
  51. #~ $max = 4286558044897590;
  52. say ":: Computing an upper-bound for a($n)";
  53. while (1) {
  54. my @terms;
  55. say ":: Computing terms <= $max";
  56. f([2], 3, $n, 2, $max, sub($k) {
  57. say "a($n) <= $k";
  58. push @terms, $k;
  59. });
  60. if (@terms) {
  61. say "\n:: Final upper-bound:\na($n) <= ", vecmin(@terms);
  62. last;
  63. }
  64. $max *= 2;
  65. }
  66. __END__
  67. :: Computing terms <= 524288
  68. :: Computing terms <= 1048576
  69. :: Computing terms <= 2097152
  70. a(9) <= 1458870
  71. a(9) <= 1414590
  72. a(9) <= 1335534
  73. :: Final upper-bound:
  74. a(9) <= 1335534
  75. perl upper-bounds.pl 0.98s user 0.00s system 99% cpu 0.988 total