prog.pl 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/perl
  2. # a(n) is the index of the smallest n-gonal number divisible by exactly n n-gonal numbers.
  3. # https://oeis.org/A358058
  4. # Known terms:
  5. # 3, 6, 12, 48, 51, 330, 1100, 702, 8120, 980, 5499, 110880, 10472, 2688, 2127411, 517104, 710640, 396480, 2761803, 4254120, 13347975, 707000, 3655827
  6. use 5.020;
  7. use ntheory qw(:all);
  8. use experimental qw(signatures);
  9. # PARI/GP program:
  10. # a(n) = if(n<3, return()); for(k=1, oo, my(t=(k*(n*k - n - 2*k + 4))\2); if(sumdiv(t, d, ispolygonal(d, n)) == n, return(k)));
  11. sub a($n) {
  12. my $count;
  13. for(my $k = 1; ; ++$k) {
  14. #my $t = divint(mulint($k, ($n*$k - $n - 2*$k + 4)), 2);
  15. my $t = rshiftint(mulint($k, ($n*$k - $n - 2*$k + 4)), 1);
  16. $count = 0;
  17. foreach my $d (divisors($t)) {
  18. if (is_polygonal($d, $n)) {
  19. ++$count;
  20. }
  21. }
  22. if ($count == $n) {
  23. return $k;
  24. }
  25. }
  26. }
  27. foreach my $n (26..100) {
  28. say "a($n) = ", a($n);
  29. }
  30. __END__