Sha256: 06810f8242a6d06e2c8d71c0ea837d7aa8dd11c45e464d06001e53b9cae3f3f3
Contents?: true
Size: 528 Bytes
Versions: 12
Compression:
Stored size: 528 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 τ n = self return @nod if defined?(@nod) square_root = Math.sqrt(n) @nod = (1..square_root.floor). map {|i| n.quo(i).to_i - (n - 1).quo(i).to_i }. reduce(:+) * 2 @nod -= 1 if square_root.integer? @nod end alias :number_of_divisors :τ alias :d :τ end
Version data entries
12 entries across 12 versions & 1 rubygems