-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog.pl
61 lines (48 loc) · 1.02 KB
/
prog.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
# a(n) is the index of the smallest n-gonal pyramidal number divisible by exactly n n-gonal pyramidal numbers.
# https://oeis.org/A358059
# Known terms:
# 6, 7, 20, 79, 90, 203, 972, 3135, 374, 283815, 31824, 2232, 10240, 144584, 70784
use 5.020;
use warnings;
use ntheory qw(:all);
use experimental qw(signatures);
sub pyramidal ($k, $r) {
divint(vecprod($k, ($k+1), ($r-2)*$k + (5-$r)), 6);
}
sub a($n) {
my %table;
for(my $k = 1; ; ++$k) {
my $t = pyramidal($k, $n);
undef $table{$t};
my $count = 0;
foreach my $d (divisors($t)) {
if (exists $table{$d}) {
++$count;
last if ($count > $n);
}
}
if ($count == $n) {
return $k;
}
}
}
foreach my $n (3..100) {
say "a($n) = ", a($n);
}
__END__
a(3) = 6
a(4) = 7
a(5) = 20
a(6) = 79
a(7) = 90
a(8) = 203
a(9) = 972
a(10) = 3135
a(11) = 374
a(12) = 283815
a(13) = 31824
a(14) = 2232
a(15) = 10240
a(16) = 144584
a(17) = 70784