recursive_upper-bounds.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/perl
  2. # a(n) is the least number that has exactly n divisors with sum of digits n.
  3. # https://oeis.org/A359444
  4. use 5.020;
  5. use warnings;
  6. use experimental qw(signatures);
  7. use ntheory qw(:all);
  8. use Math::AnyNum qw(:overload);
  9. sub smallest_number_with_n_divisors ($threshold, $least_solution = Inf, $k = 1, $max_a = Inf, $sigma0 = 1, $n = 1) {
  10. state $max = Inf;
  11. if ($sigma0 == $threshold) {
  12. if ($n < $max) {
  13. say "a($threshold) <= $n";
  14. $max = $n;
  15. }
  16. return $n;
  17. }
  18. if ($sigma0 > $threshold) {
  19. return $least_solution;
  20. }
  21. my $p = nth_prime($k);
  22. for (my $a = 1 ; $a <= $max_a ; ++$a) {
  23. $n *= $p;
  24. last if ($n > $least_solution);
  25. my $count = 0;
  26. foreach my $d (divisors($n)) {
  27. if (vecsum(todigits($d)) == $threshold) {
  28. ++$count;
  29. }
  30. }
  31. $least_solution = __SUB__->($threshold, $least_solution, $k + 1, $a, $count, $n);
  32. }
  33. return $least_solution;
  34. }
  35. my $n = 34;
  36. say "a($n) <= ", smallest_number_with_n_divisors($n);
  37. __END__
  38. a(28) <= 8147739600
  39. a(29) <= 7138971840
  40. a(31) <= 37246809600
  41. a(32) <= 37736899200
  42. a(33) <= 1045524480
  43. a(34) <= 25878772920