Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -0,0 +1,30 @@
|
|||
import Control.Parallel.Strategies
|
||||
import Control.DeepSeq
|
||||
import Data.List
|
||||
import Data.Function
|
||||
|
||||
nums = [112272537195293
|
||||
,112582718962171
|
||||
,112272537095293
|
||||
,115280098190773
|
||||
,115797840077099
|
||||
,1099726829285419]
|
||||
|
||||
factors :: Integral a => a -> [a]
|
||||
factors n | n `rem` 2 == 0 = [2] ++ factors (n `quot` 2)
|
||||
| otherwise = y
|
||||
where y = [x | x <- [3,5..ceiling . sqrt $ fromIntegral n]
|
||||
++ [n], n `rem` x == 0]
|
||||
|
||||
minPrimes :: [Integer] -> (Integer, [Integer])
|
||||
minPrimes ns = (\(x, y) -> (x, y:factors ( x `quot` y))) $
|
||||
maximumBy (compare `on` snd)
|
||||
(zip ns (parMap rdeepseq (head . factors) ns))
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn . concat $ ["The number with the "
|
||||
, "largest minimum prime factor was:\n"
|
||||
, show x, "\nWith factors: "]
|
||||
mapM_ print y
|
||||
where (x, y) = (minPrimes nums)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
procedure main(A)
|
||||
threads := []
|
||||
L := list(*A)
|
||||
every i := 1 to *A do put(threads, thread L[i] := primedecomp(A[i]))
|
||||
every wait(!threads)
|
||||
|
||||
maxminF := L[maxminI := 1][1]
|
||||
every i := 2 to *L do if maxminF <:= L[i][1] then maxminI := i
|
||||
every writes((A[maxminI]||": ")|(!L[maxminI]||" ")|"\n")
|
||||
end
|
||||
|
||||
procedure primedecomp(n) #: return a list of factors
|
||||
every put(F := [], genfactors(n))
|
||||
return F
|
||||
end
|
||||
|
||||
link factors
|
||||
Loading…
Add table
Add a link
Reference in a new issue