primes :: [Integer] primes = 2 : filter (null . tail . primeFactors) [3, 5 ..] primeFactors :: Integer -> [Integer] primeFactors n = factor n primes where factor n (p : ps) | p * p > n = [n] | n `mod` p == 0 = p : factor (n `div` p) (p : ps) | otherwise = factor n ps groupFactors :: [Integer] -> [[Integer]] groupFactors = gf [] where gf acc lst | null lst = reverse acc | null acc = gf [[p,1]] ps -- | p == head (head acc) = gf ([p, head (tail (head acc)) + 1]:tail acc) ps -- | otherwise = gf ([p,1]:acc) ps where p = head lst ps = tail lst nDiv :: Integer -> Integer nDiv n = product (map ((1+) . head . tail) (groupFactors (primeFactors n))) fm :: Integer -> Integer -> Integer fm m n | triDiv n > m = n*(n+1) `div` 2 | otherwise = fm m (n+1) where triDiv n | even n = nDiv (n `div` 2)*nDiv (n+1) | otherwise = nDiv n*nDiv ((n+1) `div` 2)

λ> :set +s λ> fm 500 1 76576500 (0.20 secs, 199,313,728 bytes) λ>

— Me@2023-05-04 09:51:19 AM

.

.

2023.05.04 Thursday (c) All rights reserved by ACHK

You must be logged in to post a comment.