infinitary_divisors.sf 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/ruby
  2. # Generate the infinitary divisors (or i-divisors) of n.
  3. # See also:
  4. # https://oeis.org/A049417
  5. # https://oeis.org/A077609
  6. func infinitary_divisors(n) {
  7. var d = [1]
  8. for p,e in (n.factor_exp) {
  9. var r = 1
  10. d << gather {
  11. for j in (1..e) {
  12. r *= p
  13. take(d.map {|u| u*r }...) if (e&j == j)
  14. }
  15. }...
  16. }
  17. return d.sort
  18. }
  19. for n in (1..20) {
  20. say "i-divisors of #{n}: #{infinitary_divisors(n)}"
  21. assert_eq(infinitary_divisors(n).len, n.isigma0)
  22. assert_eq(infinitary_divisors(n).sum, n.isigma)
  23. assert_eq(infinitary_divisors(n), n.idivisors)
  24. }
  25. __END__
  26. i-divisors of 1: [1]
  27. i-divisors of 2: [1, 2]
  28. i-divisors of 3: [1, 3]
  29. i-divisors of 4: [1, 4]
  30. i-divisors of 5: [1, 5]
  31. i-divisors of 6: [1, 2, 3, 6]
  32. i-divisors of 7: [1, 7]
  33. i-divisors of 8: [1, 2, 4, 8]
  34. i-divisors of 9: [1, 9]
  35. i-divisors of 10: [1, 2, 5, 10]
  36. i-divisors of 11: [1, 11]
  37. i-divisors of 12: [1, 3, 4, 12]
  38. i-divisors of 13: [1, 13]
  39. i-divisors of 14: [1, 2, 7, 14]
  40. i-divisors of 15: [1, 3, 5, 15]
  41. i-divisors of 16: [1, 16]
  42. i-divisors of 17: [1, 17]
  43. i-divisors of 18: [1, 2, 9, 18]
  44. i-divisors of 19: [1, 19]
  45. i-divisors of 20: [1, 4, 5, 20]