Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Content added Content deleted
Line 306: | Line 306: | ||
countDivs n = foldr f 0 [1..floor (sqrt $ realToFrac n)] |
countDivs n = foldr f 0 [1..floor (sqrt $ realToFrac n)] |
||
where |
where |
||
f d r | n `mod` d == 0 = let y = n `div` d in if d == y then |
f d r | n `mod` d == 0 = let y = n `div` d in if d == y then r+1 else r+2 |
||
| otherwise = r |
| otherwise = r |
||
go t ((n,d):xs) | d == t = (t,n):go (succ t) xs |
go t ((n,d):xs) | d == t = (t,n):go (succ t) xs |
||
| otherwise = go t xs |
| otherwise = go t xs |