'From Squeak3.10.2 of ''5 June 2008'' [latest update: #7179] on 31 July 2008 at 8:44:13 am'!
!Integer methodsFor: 'mathematical functions' stamp: 'kwl 7/31/2008 08:42'!
numberOfDivisorCombinations
"Answer the number of divisor combinations
of the receiver, or nil if there are none."
"Examples from http://www.research.att.com/~njas/sequences/A072938"
"{1. 2. 6. 12. 60. 360. 2520. 4096} collect: [:each | each numberOfDivisorCombinations]"
| remainder primesBag probe occurences |
(remainder := self abs) < 1
ifTrue: [^ nil].
primesBag := Dictionary new.
probe := 2.
["while there are prime divisors"
remainder = 1]
whileFalse: ["check with probe using #gcd:"
(remainder gcd: probe) = 1
ifTrue: ["skip to next odd"
probe := (probe = 2
ifTrue: [1] ifFalse: [2]) + probe]
ifFalse: ["found some"
occurences := primesBag at: probe ifAbsent: 0.
primesBag at: probe put: 1 + occurences.
remainder := remainder / probe]].
"formula at http://www.brefeld.homepage.t-online.de/teilbarkeit.html"
^ primesBag values
inject: 1
into: [:combs :contribs | contribs + 1 * combs]! !