Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Content added Content deleted
(added Haskell) |
|||
Line 298: | Line 298: | ||
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 |
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
|||
<lang haskell>import Data.List (nub) |
|||
import Text.Printf (printf) |
|||
divisorCount :: Int -> Int |
|||
divisorCount = length . nub . foldr (\(a, b) r -> a:b:r) [] . divisors |
|||
where |
|||
divisors n = [(x, n `div` x) | x <- [1..ceiling (sqrt $ realToFrac n)], n `mod` x == 0] |
|||
sequence_A069654 :: [(Int,Int)] |
|||
sequence_A069654 = go 1 nDivCount |
|||
where |
|||
nDivCount = (,) <*> divisorCount <$> [1..] |
|||
go t ((n,d):xs) |
|||
| d == t = (d,n) : go (succ t) xs |
|||
| otherwise = go t xs |
|||
main :: IO () |
|||
main = mapM_ (uncurry(printf "a(%2d)=%5d\n")) $ take 15 sequence_A069654</lang> |
|||
{{out}} |
|||
<pre>a( 1)= 1 |
|||
a( 2)= 2 |
|||
a( 3)= 4 |
|||
a( 4)= 6 |
|||
a( 5)= 16 |
|||
a( 6)= 18 |
|||
a( 7)= 64 |
|||
a( 8)= 66 |
|||
a( 9)= 100 |
|||
a(10)= 112 |
|||
a(11)= 1024 |
|||
a(12)= 1035 |
|||
a(13)= 4096 |
|||
a(14)= 4288 |
|||
a(15)= 4624 |
|||
</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |
||
<lang j> |
<lang j> |