1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/ruby
- # Sum and count of the k-powerfree unitary divisors of n.
- # See also:
- # https://oeis.org/A092261
- # https://oeis.org/A056671
- func powerfree_usigma0(n, k=2) {
- n.factor_prod {|_,e|
- (e < k) ? 2 : 1
- }
- }
- func powerfree_usigma(n, k=2, j=1) {
- return powerfree_usigma0(n, k) if (j == 0)
- var prod = 1
- for p,e in (n.factor_exp) {
- e < k || next
- #prod *= usigma(p**e, j)
- prod *= (p**(e*j) + 1)
- }
- return prod
- }
- for n in (1..20) {
- say "sum of squarefree unitary divisors of #{n} is #{powerfree_usigma(n, 2)}"
- assert_eq(powerfree_usigma(n, 2), 2.powerfree_udivisors(n).sum)
- assert_eq(powerfree_usigma(n, 3), 3.powerfree_udivisors(n).sum)
- assert_eq(powerfree_usigma(n, 4), 4.powerfree_udivisors(n).sum)
- assert_eq(powerfree_usigma(n, 2, 0), 2.powerfree_udivisors(n).len)
- assert_eq(powerfree_usigma(n, 3, 0), 3.powerfree_udivisors(n).len)
- assert_eq(powerfree_usigma(n, 4, 0), 4.powerfree_udivisors(n).len)
- assert_eq(powerfree_usigma(n, 2, 2), 2.powerfree_udivisors(n).sum { _**2 })
- assert_eq(powerfree_usigma(n, 3, 2), 3.powerfree_udivisors(n).sum { _**2 })
- assert_eq(powerfree_usigma(n, 4, 2), 4.powerfree_udivisors(n).sum { _**2 })
- assert_eq(powerfree_usigma(n, 2, 3), 2.powerfree_udivisors(n).sum { _**3 })
- assert_eq(powerfree_usigma(n, 3, 3), 3.powerfree_udivisors(n).sum { _**3 })
- assert_eq(powerfree_usigma(n, 4, 3), 4.powerfree_udivisors(n).sum { _**3 })
- }
- __END__
- sum of squarefree unitary divisors of 1 is 1
- sum of squarefree unitary divisors of 2 is 3
- sum of squarefree unitary divisors of 3 is 4
- sum of squarefree unitary divisors of 4 is 1
- sum of squarefree unitary divisors of 5 is 6
- sum of squarefree unitary divisors of 6 is 12
- sum of squarefree unitary divisors of 7 is 8
- sum of squarefree unitary divisors of 8 is 1
- sum of squarefree unitary divisors of 9 is 1
- sum of squarefree unitary divisors of 10 is 18
- sum of squarefree unitary divisors of 11 is 12
- sum of squarefree unitary divisors of 12 is 4
- sum of squarefree unitary divisors of 13 is 14
- sum of squarefree unitary divisors of 14 is 24
- sum of squarefree unitary divisors of 15 is 24
- sum of squarefree unitary divisors of 16 is 1
- sum of squarefree unitary divisors of 17 is 18
- sum of squarefree unitary divisors of 18 is 3
- sum of squarefree unitary divisors of 19 is 20
- sum of squarefree unitary divisors of 20 is 6
|