Count in factors: Difference between revisions
Content added Content deleted
(add CoffeeScript example) |
(→{{header|Haskell}}: e) |
||
Line 575: | Line 575: | ||
Using <code>factorize</code> function from the [[Prime_decomposition#Haskell|prime decomposition]] task, |
Using <code>factorize</code> function from the [[Prime_decomposition#Haskell|prime decomposition]] task, |
||
<lang haskell> |
<lang haskell>import Data.List (intercalate) |
||
showFactors n = show n ++ " = " ++ (intercalate " * " . map show . factorize) n</lang> |
|||
"1" |
|||
Output:<small> |
|||
"2" |
|||
<lang haskell>*Main> print 1 >> mapM_ (putStrLn . showFactors) [2..] |
|||
"3" |
|||
1 |
|||
2 = 2 |
|||
"5" |
|||
3 = 3 |
|||
⚫ | |||
"7" |
|||
5 = 5 |
|||
⚫ | |||
6 = 2 * 3 |
|||
7 = 7 |
|||
⚫ | |||
"11" |
|||
9 = 3 * 3 |
|||
10 = 2 * 5 |
|||
11 = 11 |
|||
⚫ | |||
13 = 13 |
|||
. . . |
|||
*Main> mapM_ (putStrLn . showFactors) [2144..] |
|||
⚫ | |||
2145 = 3 * 5 * 11 * 13 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
2150 = 2 * 5 * 5 * 43 |
|||
⚫ | |||
2152 = 2 * 2 * 2 * 269 |
|||
2153 = 2153 |
|||
⚫ | |||
2155 = 5 * 431 |
|||
. . . |
. . . |
||
*Main |
*Main> mapM_ (putStrLn . showFactors ) [1231231232155..] |
||
1231231232155 = 5 * 246246246431 |
|||
⚫ | |||
1231231232156 = 2 * 2 * 37 * 113 * 73620619 |
|||
1231231232157 = 3 * 11287 * 36361337 |
|||
⚫ | |||
1231231232158 = 2 * 2039 * 4643 * 65027 |
|||
⚫ | |||
1231231232159 = 1231231232159 |
|||
⚫ | |||
1231231232160 = 2 * 2 * 2 * 2 * 2 * 3 * 3 * 5 * 61 * 71 * 197419 |
|||
⚫ | |||
1231231232161 = 7 * 175890176023 |
|||
⚫ | |||
1231231232162 = 2 * 19 * 32400821899 |
|||
⚫ | |||
1231231232163 = 3 * 410410410721 |
|||
⚫ | |||
1231231232164 = 2 * 2 * 307807808041 |
|||
"2153" |
|||
1231231232165 = 5 * 11 * 29 * 47 * 16424081 |
|||
⚫ | |||
. . .</lang> |
. . .</lang></small> |
||
The real solution seems to have to be some sort of a segmented offset sieve of Eratosthenes, storing factors in array's cells instead of just marks. That way the speed of production might not be diminishing as much. |
The real solution seems to have to be some sort of a segmented offset sieve of Eratosthenes, storing factors in array's cells instead of just marks. That way the speed of production might not be diminishing as much. |
||