prog_2.pl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 %table;
  13. my $count;
  14. for(my $k = 1; ; ++$k) {
  15. #my $t = divint(mulint($k, ($n*$k - $n - 2*$k + 4)), 2);
  16. my $t = rshiftint(mulint($k, ($n*$k - $n - 2*$k + 4)), 1);
  17. undef $table{$t};
  18. $count = 0;
  19. foreach my $d (divisors($t)) {
  20. if (exists $table{$d}) {
  21. ++$count;
  22. }
  23. }
  24. if ($count == $n) {
  25. return $k;
  26. }
  27. }
  28. }
  29. foreach my $n (3..100) {
  30. say "a($n) = ", a($n);
  31. }
  32. __END__