Weird numbers
func is_pseudoperfect(n, d = n.divisors.first(-1), s = d.sum, m = d.end) {
return false if (m < 0)
while (d[m] > n) {
s -= d[m--]
}
return true if (n == s)
return true if (d[m] == n)
__FUNC__(n-d[m], d, s-d[m], m-1) || __FUNC__(n, d, s-d[m], m-1)
}
func is_weird(n) {
(n.sigma > 2*n) && !is_pseudoperfect(n)
}
var w = (1..Inf -> lazy.grep(is_weird).first(25))
say "The first 25 weird numbers:\n#{w.join(' ')}"Output:
Last updated
Was this helpful?