Abundant odd numbers

func is_abundant(n) {
    n.sigma > 2*n
}

func odd_abundants (from = 1) {
     from =  (from + 2)//3
     from += (from%2 - 1)
     3*from .. Inf `by` 6 -> lazy.grep(is_abundant)
}

say         " Index |      Number | proper divisor sum"
const sep = "-------+-------------+-------------------\n"
const fstr = "%6s | %11s | %11s\n"

print sep

odd_abundants().first(25).each_kv {|k,n|
    printf(fstr, k+1, n, n.sigma-n)
}

with (odd_abundants().nth(1000)) {|n|
    printf(sep + fstr, 1000, n, n.sigma-n)
}

with(odd_abundants(1e9).first) {|n|
    printf(sep + fstr, '***', n, n.sigma-n)
}

Output:

Last updated

Was this helpful?