-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_usigma.sf
66 lines (53 loc) · 1.97 KB
/
power_usigma.sf
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
#!/usr/bin/ruby
# Sum and count of the k-th power unitary divisors of n.
# See also:
# https://oeis.org/A056624
func power_usigma0(n, k) {
n.factor_prod {|_,e|
(e % k == 0) ? 2 : 1
}
}
func power_usigma(n, k=2, j=1) {
return power_usigma0(n, k) if (j == 0)
var prod = 1
for p,e in (n.factor_exp) {
if (e % k == 0) {
#prod *= usigma(p**e, j)
prod *= (p**(e*j) + 1)
}
}
return prod
}
for n in (1..20) {
say "sum of square unitary divisors of #{n} is #{power_usigma(n, 2)}"
assert_eq(power_usigma(n, 2), 2.power_udivisors(n).sum)
assert_eq(power_usigma(n, 3), 3.power_udivisors(n).sum)
assert_eq(power_usigma(n, 4), 4.power_udivisors(n).sum)
assert_eq(power_usigma(n, 2, 2), 2.power_udivisors(n).sum { _**2 })
assert_eq(power_usigma(n, 3, 2), 3.power_udivisors(n).sum { _**2 })
assert_eq(power_usigma(n, 4, 2), 4.power_udivisors(n).sum { _**2 })
assert_eq(power_usigma(n, 2, 3), 2.power_udivisors(n).sum { _**3 })
assert_eq(power_usigma(n, 3, 3), 3.power_udivisors(n).sum { _**3 })
assert_eq(power_usigma(n, 4, 3), 4.power_udivisors(n).sum { _**3 })
}
__END__
sum of square unitary divisors of 1 is 1
sum of square unitary divisors of 2 is 1
sum of square unitary divisors of 3 is 1
sum of square unitary divisors of 4 is 5
sum of square unitary divisors of 5 is 1
sum of square unitary divisors of 6 is 1
sum of square unitary divisors of 7 is 1
sum of square unitary divisors of 8 is 1
sum of square unitary divisors of 9 is 10
sum of square unitary divisors of 10 is 1
sum of square unitary divisors of 11 is 1
sum of square unitary divisors of 12 is 5
sum of square unitary divisors of 13 is 1
sum of square unitary divisors of 14 is 1
sum of square unitary divisors of 15 is 1
sum of square unitary divisors of 16 is 17
sum of square unitary divisors of 17 is 1
sum of square unitary divisors of 18 is 10
sum of square unitary divisors of 19 is 1
sum of square unitary divisors of 20 is 5