-
Notifications
You must be signed in to change notification settings - Fork 34
/
inverse_of_usigma_function.pl
52 lines (36 loc) · 1.32 KB
/
inverse_of_usigma_function.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
#!/usr/bin/perl
# Given a positive integer `n`, this algorithm finds all the numbers k
# such that usigma(k) = n, where `usigma(k)` is the sum of the unitary divisors of `k`.
# usigma(n) is multiplicative with usigma(p^k) = p^k + 1.
# See also:
# https://oeis.org/A034448 -- usigma(n)
# https://home.gwu.edu/~maxal/gpscripts/
use utf8;
use 5.020;
use strict;
use warnings;
use ntheory qw(:all);
use experimental qw(signatures);
sub inverse_usigma ($n) {
my %r = (1 => [1]);
foreach my $d (divisors($n)) {
my $D = subint($d, 1);
is_prime_power($D) || next;
my %temp;
foreach my $f (divisors(divint($n, $d))) {
if (exists $r{$f}) {
push @{$temp{mulint($f, $d)}}, map { mulint($D, $_) }
grep { gcd($D, $_) == 1 } @{$r{$f}};
}
}
while (my ($key, $value) = each(%temp)) {
push @{$r{$key}}, @$value;
}
}
return if not exists $r{$n};
return sort { $a <=> $b } @{$r{$n}};
}
my $n = 186960;
say "Solutions for usigma(x) = $n: ", join(' ', inverse_usigma($n));
__END__
Solutions for usigma(x) = 186960: 90798 108558 109046 113886 116835 120620 123518 123554 130844 131868 136419 138651 145484 148004 153495 155795 163503 163583 165771 166463 173907 174899 176823 179147 182003 185579 186089 186959