Count in factors: Difference between revisions
→{{header|Haskell}}: e
(add CoffeeScript example) |
(→{{header|Haskell}}: e) |
||
Line 575:
Using <code>factorize</code> function from the [[Prime_decomposition#Haskell|prime decomposition]] task,
<lang haskell>
Output:<small>
<lang haskell>*Main> print 1 >> mapM_ (putStrLn . showFactors) [2..]
1
5 = 5
▲"2 * 2 * 2"
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
1231231232155 = 5 * 246246246431
▲"2 * 2 * 2 * 2 * 2 * 67"
1231231232157 = 3 * 11287 * 36361337
▲"2 * 29 * 37"
1231231232158 = 2 * 2039 * 4643 * 65027
▲"19 * 113"
1231231232159 = 1231231232159
▲"2 * 2 * 3 * 179"
1231231232160 = 2 * 2 * 2 * 2 * 2 * 3 * 3 * 5 * 61 * 71 * 197419
▲"7 * 307"
1231231232161 = 7 * 175890176023
▲"2 * 5 * 5 * 43"
1231231232162 = 2 * 19 * 32400821899
▲"3 * 3 * 239"
1231231232163 = 3 * 410410410721
▲"2 * 2 * 2 * 269"
1231231232164 = 2 * 2 * 307807808041
1231231232165 = 5 * 11 * 29 * 47 * 16424081
▲"2 * 3 * 359"
. . .</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.
|