smooth_upper-bounds.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Math::GMPz;
  8. use ntheory qw(:all);
  9. sub check_valuation ($n, $p) {
  10. if ($p == 2) {
  11. return valuation($n, $p) < 7;
  12. }
  13. if ($p == 3) {
  14. return valuation($n, $p) < 4;
  15. }
  16. if ($p == 5) {
  17. return valuation($n, $p) < 3;
  18. }
  19. if ($p == 7) {
  20. return valuation($n, $p) < 3;
  21. }
  22. if ($p == 11) {
  23. return valuation($n, $p) < 2;
  24. }
  25. ($n % $p) != 0;
  26. }
  27. sub smooth_numbers ($limit, $primes) {
  28. my @h = (1);
  29. foreach my $p (@$primes) {
  30. say "Prime: $p";
  31. foreach my $n (@h) {
  32. if ($n * $p <= $limit and check_valuation($n, $p)) {
  33. push @h, $n * $p;
  34. }
  35. }
  36. }
  37. return \@h;
  38. }
  39. sub isok ($n, $k) {
  40. my $count = 0;
  41. foreach my $d(divisors($n)) {
  42. if (vecsum(todigits($d)) == $k) {
  43. ++$count;
  44. }
  45. }
  46. $count == $k;
  47. }
  48. my @smooth_primes = @{primes(101)};
  49. my $h = smooth_numbers(14803438640, \@smooth_primes);
  50. say "\nFound: ", scalar(@$h), " terms";
  51. my $max = 'inf';
  52. my $k = 35;
  53. foreach my $n (@$h) {
  54. if ($n % 2 == 0 and $n < $max and isok($n, $k)) {
  55. $max = $n;
  56. say "a($k) <= $n";
  57. }
  58. }
  59. __END__
  60. a(28) <= 413736400
  61. a(29) <= 1081662400
  62. a(30) = 73670520
  63. a(31) <= 3301916800
  64. a(32) <= 2325202880
  65. a(33) <= 407578080
  66. a(34) <= 4803438640
  67. a(35) <= 14456653120
  68. a(36) = 12598740