unitary_powerfree_sigma.sf 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/ruby
  2. # Sum of the unitary k-powerfree divisors of n.
  3. # See also:
  4. # https://oeis.org/A092261
  5. func unitary_powerfree_sigma(n, k=2, j=1) {
  6. var prod = 1
  7. for p,e in (n.factor_exp) {
  8. e < k || next
  9. #prod *= usigma(p**e, j)
  10. prod *= (p**(e*j) + 1)
  11. }
  12. return prod
  13. }
  14. for n in (1..20) {
  15. say "sum of unitary squarefree divisors of #{n} is #{unitary_powerfree_sigma(n, 2)}"
  16. assert_eq(unitary_powerfree_sigma(n, 2), n.udivisors.grep { .is_powerfree(2) }.sum)
  17. assert_eq(unitary_powerfree_sigma(n, 3), n.udivisors.grep { .is_powerfree(3) }.sum)
  18. assert_eq(unitary_powerfree_sigma(n, 4), n.udivisors.grep { .is_powerfree(4) }.sum)
  19. assert_eq(unitary_powerfree_sigma(n, 2, 2), n.udivisors.grep { .is_powerfree(2) }.sum { _**2 })
  20. assert_eq(unitary_powerfree_sigma(n, 3, 2), n.udivisors.grep { .is_powerfree(3) }.sum { _**2 })
  21. assert_eq(unitary_powerfree_sigma(n, 4, 2), n.udivisors.grep { .is_powerfree(4) }.sum { _**2 })
  22. assert_eq(unitary_powerfree_sigma(n, 2, 3), n.udivisors.grep { .is_powerfree(2) }.sum { _**3 })
  23. assert_eq(unitary_powerfree_sigma(n, 3, 3), n.udivisors.grep { .is_powerfree(3) }.sum { _**3 })
  24. assert_eq(unitary_powerfree_sigma(n, 4, 3), n.udivisors.grep { .is_powerfree(4) }.sum { _**3 })
  25. }
  26. __END__
  27. sum of unitary squarefree divisors of 1 is 1
  28. sum of unitary squarefree divisors of 2 is 3
  29. sum of unitary squarefree divisors of 3 is 4
  30. sum of unitary squarefree divisors of 4 is 1
  31. sum of unitary squarefree divisors of 5 is 6
  32. sum of unitary squarefree divisors of 6 is 12
  33. sum of unitary squarefree divisors of 7 is 8
  34. sum of unitary squarefree divisors of 8 is 1
  35. sum of unitary squarefree divisors of 9 is 1
  36. sum of unitary squarefree divisors of 10 is 18
  37. sum of unitary squarefree divisors of 11 is 12
  38. sum of unitary squarefree divisors of 12 is 4
  39. sum of unitary squarefree divisors of 13 is 14
  40. sum of unitary squarefree divisors of 14 is 24
  41. sum of unitary squarefree divisors of 15 is 24
  42. sum of unitary squarefree divisors of 16 is 1
  43. sum of unitary squarefree divisors of 17 is 18
  44. sum of unitary squarefree divisors of 18 is 3
  45. sum of unitary squarefree divisors of 19 is 20
  46. sum of unitary squarefree divisors of 20 is 6