prog.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/perl
  2. # a(1)=2048. For n>1, a(n) is the LCM of a(n-1) and A140635(a(n-1)).
  3. # https://oeis.org/A351162
  4. # Previously known terms:
  5. # 2048, 30720, 645120, 7096320, 92252160, 1383782400, 23524300800
  6. # This sequence converges at n = 35. I.e.: a(n) = a(35) for all n >= 36. - Daniel Suteu, Mar 15 2022
  7. use 5.020;
  8. use warnings;
  9. use experimental qw(signatures);
  10. use ntheory qw(nth_prime divisor_sum);
  11. use Math::AnyNum qw(:overload lcm);
  12. sub smallest_number_with_n_divisors ($threshold, $least_solution = Inf, $k = 1, $max_a = Inf, $solutions = 1, $n = 1) {
  13. if ($solutions == $threshold) {
  14. return $n;
  15. }
  16. if ($solutions > $threshold) {
  17. return $least_solution;
  18. }
  19. my $p = nth_prime($k);
  20. for (my $a = 1 ; $a <= $max_a ; ++$a) {
  21. $n *= $p;
  22. last if ($n > $least_solution);
  23. $least_solution = __SUB__->($threshold, $least_solution, $k + 1, $a, $solutions * ($a + 1), $n);
  24. }
  25. return $least_solution;
  26. }
  27. my $u = 2048;
  28. say "a(1) = $u";
  29. foreach my $n (2..100) {
  30. my $sigma0 = divisor_sum($u, 0);
  31. my $v = lcm($u, smallest_number_with_n_divisors($sigma0));
  32. say "a($n) = $v";
  33. $u = $v;
  34. }
  35. __END__
  36. a(1) = 2048
  37. a(2) = 30720
  38. a(3) = 645120
  39. a(4) = 7096320
  40. a(5) = 92252160
  41. a(6) = 1383782400
  42. a(7) = 23524300800
  43. a(8) = 446961715200
  44. a(9) = 10280119449600
  45. a(10) = 71960836147200
  46. a(11) = 2086864248268800
  47. a(12) = 64692791696332800
  48. a(13) = 582235125266995200
  49. a(14) = 21542699634878822400
  50. a(15) = 883250685030031718400
  51. a(16) = 37979779456291363891200
  52. a(17) = 189898897281456819456000
  53. a(18) = 8925248172228470514432000
  54. a(19) = 473038153128108937264896000
  55. a(20) = 5203419684409198309913856000
  56. a(21) = 307001761380142700284917504000
  57. a(22) = 18727107444188704717379967744000
  58. a(23) = 1254716198760643216064457838848000
  59. a(24) = 89084850112005668340576506558208000
  60. a(25) = 1158103051456073688427494585256704000
  61. a(26) = 84541522756293379255207104723739392000
  62. a(27) = 6678780297747176961161361273175411968000
  63. a(28) = 554338764713015687776392985673559193344000
  64. a(29) = 49336150059458396212098975724946768207616000
  65. a(30) = 345353050416208773484692830074627377453312000
  66. a(31) = 33499245890372251028015204517238855612971264000
  67. a(32) = 3383423834927597353829535656241124416910097664000
  68. a(33) = 348492654997542527444442172592835814941740059392000
  69. a(34) = 37288714084737050436555312467433432198766186354944000
  70. a(35) = 4064469835236338497584529058950244109665514312688896000
  71. a(36) = 4064469835236338497584529058950244109665514312688896000