1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/ruby
- # Generate the infinitary divisors (or i-divisors) of n.
- # See also:
- # https://oeis.org/A049417
- # https://oeis.org/A077609
- func infinitary_divisors(n) {
- var d = [1]
- for p,e in (n.factor_exp) {
- var r = 1
- d << gather {
- for j in (1..e) {
- r *= p
- take(d.map {|u| u*r }...) if (e&j == j)
- }
- }...
- }
- return d.sort
- }
- for n in (1..20) {
- say "i-divisors of #{n}: #{infinitary_divisors(n)}"
- assert_eq(infinitary_divisors(n).len, n.isigma0)
- assert_eq(infinitary_divisors(n).sum, n.isigma)
- assert_eq(infinitary_divisors(n), n.idivisors)
- }
- __END__
- i-divisors of 1: [1]
- i-divisors of 2: [1, 2]
- i-divisors of 3: [1, 3]
- i-divisors of 4: [1, 4]
- i-divisors of 5: [1, 5]
- i-divisors of 6: [1, 2, 3, 6]
- i-divisors of 7: [1, 7]
- i-divisors of 8: [1, 2, 4, 8]
- i-divisors of 9: [1, 9]
- i-divisors of 10: [1, 2, 5, 10]
- i-divisors of 11: [1, 11]
- i-divisors of 12: [1, 3, 4, 12]
- i-divisors of 13: [1, 13]
- i-divisors of 14: [1, 2, 7, 14]
- i-divisors of 15: [1, 3, 5, 15]
- i-divisors of 16: [1, 16]
- i-divisors of 17: [1, 17]
- i-divisors of 18: [1, 2, 9, 18]
- i-divisors of 19: [1, 19]
- i-divisors of 20: [1, 4, 5, 20]
|