infinitary_sigma.sf 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/ruby
  2. # Sum of infinitary divisors of n.
  3. # Multiplicative with:
  4. # If e = Sum_{k >= 0} d_k 2^k (binary representation of e), then
  5. # isigma(p^e, r) = Product_{k >= 0} (p^(r*2^k*{d_k+1}) - 1)/(p^(r*2^k) - 1)
  6. # Simplified formula, where d_k is odd in the binary representation of e (ignore even d_k):
  7. # isigma(p^e, r) = Product_{k >= 0} (p^(r * 2^k) + 1)
  8. # See also:
  9. # https://oeis.org/A049417
  10. func infinitary_sigma(n, k=1) {
  11. n.factor_prod {|p,e|
  12. e.digits(2).prod_kv {|j,d|
  13. d.is_odd ? (p**((1<<j) * k) + 1) : 1
  14. #(p**(k*(1<<j)*(d+1)) - 1)/(p**(k*(1<<j)) - 1)
  15. }
  16. }
  17. }
  18. say map(1..20, {infinitary_sigma(_, 1)})
  19. say map(1..20, {infinitary_sigma(_, 2)})
  20. say map(1..20, {infinitary_sigma(_, 3)})
  21. __END__
  22. [1, 3, 4, 5, 6, 12, 8, 15, 10, 18, 12, 20, 14, 24, 24, 17, 18, 30, 20, 30]
  23. [1, 5, 10, 17, 26, 50, 50, 85, 82, 130, 122, 170, 170, 250, 260, 257, 290, 410, 362, 442]
  24. [1, 9, 28, 65, 126, 252, 344, 585, 730, 1134, 1332, 1820, 2198, 3096, 3528, 4097, 4914, 6570, 6860, 8190]