prog.pl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/perl
  2. # a(n) is the smallest n-gonal pyramidal number divisible by exactly n n-gonal pyramidal numbers.
  3. # https://oeis.org/A358860
  4. # Known terms:
  5. # 56, 140, 4200, 331800, 611520, 8385930
  6. # PARI/GP program:
  7. # pyramidal(k,r) = (k*(k+1)*((r-2)*k + (5-r)))\6;
  8. # ispyramidal(n,r) = pyramidal(sqrtnint(6*n\(r-2) + sqrtnint(n, 3), 3), r) == n;
  9. # a(n) = if(n<3, return()); for(k=1, oo, my(t=pyramidal(k,n)); if(sumdiv(t, d, ispyramidal(d, n)) == n, return(t)));
  10. use 5.020;
  11. use warnings;
  12. use ntheory qw(:all);
  13. use experimental qw(signatures);
  14. sub pyramidal ($k, $r) {
  15. divint(vecprod($k, ($k+1), ($r-2)*$k + (5-$r)), 6);
  16. }
  17. sub is_pyramidal($n, $r) {
  18. my $k = rootint(divint(mulint($n, 6), $r-2) + rootint($n, 3), 3);
  19. pyramidal($k, $r) == $n;
  20. }
  21. sub a($n) {
  22. for(my $k = 1; ; ++$k) {
  23. my $t = pyramidal($k, $n);
  24. my $count = 0;
  25. foreach my $d (divisors($t)) {
  26. if (is_pyramidal($d, $n)) {
  27. ++$count;
  28. last if ($count > $n);
  29. }
  30. }
  31. if ($count == $n) {
  32. return $t;
  33. }
  34. }
  35. }
  36. foreach my $n (3..100) {
  37. say "a($n) = ", a($n);
  38. }
  39. __END__
  40. a(3) = 56
  41. a(4) = 140
  42. a(5) = 4200
  43. a(6) = 331800
  44. a(7) = 611520
  45. a(8) = 8385930
  46. a(9) = 1071856800
  47. a(10) = 41086892000
  48. a(11) = 78540000
  49. # Incorrect terms:
  50. a(9) = 2334564960
  51. a(10) = 4775553032250
  52. a(11) = 1564399200