-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcn_product_of_4_consecutive_integers.pl
80 lines (60 loc) · 1.91 KB
/
hcn_product_of_4_consecutive_integers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# Date: 02 July 2019
# https://github.com/trizen
# Find highly composite numbers H(n) that are the product of 4 consecutive integers.
# Known terms:
# 24, 120, 360, 840, 1680, 5040, 17297280
# See also:
# https://oeis.org/A217056
use 5.020;
use strict;
use warnings;
use Math::GMPz;
use ntheory qw(:all);
use IO::Uncompress::Bunzip2;
use experimental qw(signatures declared_refs);
local $| = 1;
prime_precalc(1e7);
sub primorial_inflation ($n) {
state %primorial;
my $tmp = Math::GMPz->new(1);
my $prod = Math::GMPz->new(1);
foreach my \@pp(factor_exp($n)) {
my ($p, $e) = @pp;
my $prim = $primorial{$p} //= do {
my $z = Math::GMPz::Rmpz_init_nobless();
Math::GMPz::Rmpz_primorial_ui($z, $p);
$z;
};
if ($e > 1) {
Math::GMPz::Rmpz_pow_ui($tmp, $prim, $e);
Math::GMPz::Rmpz_mul($prod, $prod, $tmp);
}
else {
Math::GMPz::Rmpz_mul($prod, $prod, $prim);
}
}
return $prod;
}
# "HCN.bz2" was generated by Achim Flammenkamp, and is available at:
# http://wwwhomes.uni-bielefeld.de/achim/HCN.bz2
# "HCN_primorial_deflated.txt.bz2" is a primorial deflation of each highly composite number H(n) from "HCN.bz2", such that A108951(A181815(H(n))) = H(n).
my $z = IO::Uncompress::Bunzip2->new("HCN_primorial_deflated.txt.bz2");
my $t = Math::GMPz->new(1);
my $u = Math::GMPz->new(1);
while (defined(my $line = $z->getline())) {
chomp($line);
my $hcn = primorial_inflation($line);
Math::GMPz::Rmpz_root($t, $hcn, 4);
Math::GMPz::Rmpz_set($u, $t);
Math::GMPz::Rmpz_sub_ui($t, $t, 1);
Math::GMPz::Rmpz_mul($u, $u, $t);
Math::GMPz::Rmpz_add_ui($t, $t, 2);
Math::GMPz::Rmpz_mul($u, $u, $t);
Math::GMPz::Rmpz_add_ui($t, $t, 1);
Math::GMPz::Rmpz_mul($u, $u, $t);
if ($u == $hcn) {
print $hcn, ", ";
}
}