Erdős-Nicolas numbers

func is_Erdős_Nicolas(n) {

    n.is_abundant || return false

    var sum   = 0
    var count = 0

    n.divisors.each {|d|
        ++count;         sum += d
        return count if (sum == n)
        return false if (sum >  n)
    }
}

var count = 8   # how many terms to compute

^Inf -> by(2).each {|n|
    if (is_Erdős_Nicolas(n)) { |v|
        say "#{'%8s'%n} is the sum of its first #{'%3s'%v} divisors"
        --count || break
    }
}

Output:

Last updated

Was this helpful?