powerfree_usigma.sf 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/ruby
  2. # Sum and count of the k-powerfree unitary divisors of n.
  3. # See also:
  4. # https://oeis.org/A092261
  5. # https://oeis.org/A056671
  6. func powerfree_usigma0(n, k=2) {
  7. n.factor_prod {|_,e|
  8. (e < k) ? 2 : 1
  9. }
  10. }
  11. func powerfree_usigma(n, k=2, j=1) {
  12. return powerfree_usigma0(n, k) if (j == 0)
  13. var prod = 1
  14. for p,e in (n.factor_exp) {
  15. e < k || next
  16. #prod *= usigma(p**e, j)
  17. prod *= (p**(e*j) + 1)
  18. }
  19. return prod
  20. }
  21. for n in (1..20) {
  22. say "sum of squarefree unitary divisors of #{n} is #{powerfree_usigma(n, 2)}"
  23. assert_eq(powerfree_usigma(n, 2), 2.powerfree_udivisors(n).sum)
  24. assert_eq(powerfree_usigma(n, 3), 3.powerfree_udivisors(n).sum)
  25. assert_eq(powerfree_usigma(n, 4), 4.powerfree_udivisors(n).sum)
  26. assert_eq(powerfree_usigma(n, 2, 0), 2.powerfree_udivisors(n).len)
  27. assert_eq(powerfree_usigma(n, 3, 0), 3.powerfree_udivisors(n).len)
  28. assert_eq(powerfree_usigma(n, 4, 0), 4.powerfree_udivisors(n).len)
  29. assert_eq(powerfree_usigma(n, 2, 2), 2.powerfree_udivisors(n).sum { _**2 })
  30. assert_eq(powerfree_usigma(n, 3, 2), 3.powerfree_udivisors(n).sum { _**2 })
  31. assert_eq(powerfree_usigma(n, 4, 2), 4.powerfree_udivisors(n).sum { _**2 })
  32. assert_eq(powerfree_usigma(n, 2, 3), 2.powerfree_udivisors(n).sum { _**3 })
  33. assert_eq(powerfree_usigma(n, 3, 3), 3.powerfree_udivisors(n).sum { _**3 })
  34. assert_eq(powerfree_usigma(n, 4, 3), 4.powerfree_udivisors(n).sum { _**3 })
  35. }
  36. __END__
  37. sum of squarefree unitary divisors of 1 is 1
  38. sum of squarefree unitary divisors of 2 is 3
  39. sum of squarefree unitary divisors of 3 is 4
  40. sum of squarefree unitary divisors of 4 is 1
  41. sum of squarefree unitary divisors of 5 is 6
  42. sum of squarefree unitary divisors of 6 is 12
  43. sum of squarefree unitary divisors of 7 is 8
  44. sum of squarefree unitary divisors of 8 is 1
  45. sum of squarefree unitary divisors of 9 is 1
  46. sum of squarefree unitary divisors of 10 is 18
  47. sum of squarefree unitary divisors of 11 is 12
  48. sum of squarefree unitary divisors of 12 is 4
  49. sum of squarefree unitary divisors of 13 is 14
  50. sum of squarefree unitary divisors of 14 is 24
  51. sum of squarefree unitary divisors of 15 is 24
  52. sum of squarefree unitary divisors of 16 is 1
  53. sum of squarefree unitary divisors of 17 is 18
  54. sum of squarefree unitary divisors of 18 is 3
  55. sum of squarefree unitary divisors of 19 is 20
  56. sum of squarefree unitary divisors of 20 is 6