Sha256: 639e1aee0e7eb5e3026cc0941351b7a27e26e6657e21314de1b6c0816d39abd9
Contents?: true
Size: 588 Bytes
Versions: 2
Compression:
Stored size: 588 Bytes
Contents
# coding: utf-8 class Integer # Algorithm derived from Formulas for pi(n) and the n-th prime by Sebastian # Martin Ruiz and Jonathan Sondow [arXiv:math/0210312v2 [math.NT]] # Returns the number of divisors of self def τ # TODO: Consider something simpler, and perhaps faster, like # primaries.map(&:last).map(&:succ).reduce(:*) n = self return @nod if defined?(@nod) @nod = (1..isqrt). map {|i| n.quo(i).to_i - (n - 1).quo(i).to_i }. reduce(:+) * 2 @nod -= 1 if square? @nod end alias :number_of_divisors :τ alias :d :τ end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
numb-0.152.0 | lib/numb/number_of_divisors.rb |
numb-0.138.0 | lib/numb/number_of_divisors.rb |