Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

Content added Content deleted
Line 303: Line 303:


sequence_A069654 :: [(Int,Int)]
sequence_A069654 :: [(Int,Int)]
sequence_A069654 = go 1 nDivCount
sequence_A069654 = go 1 $ (,) <*> length . divisors <$> [1..]
where
where
nDivCount = (,) <*> length . divisors <$> [1..]
divisors n = [1..floor (sqrt $ realToFrac n)] >>= \x -> do
divisors n = [1..floor (sqrt $ realToFrac n)] >>= \x -> do
guard (n `mod` x == 0)
guard (n `mod` x == 0)
let y = n `div` x
let y = n `div` x
if x == y then [x] else [x,y]
if x == y then [x] else [x,y]
go t ((n,d):xs)
go t ((n,d):xs) | d == t = (t,n):go (succ t) xs
| d == t = (t,n):go (succ t) xs
| otherwise = go t xs
| otherwise = go t xs


main :: IO ()
main :: IO ()