Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (16 sloc) 470 Bytes
import EulerMath.Primes
import EulerMath.Divisors
firstPrimeFactor :: Integer -> Integer
firstPrimeFactor n = head [ d | d <- primesUpTo n, mod n d == 0]
reduceByNextPrime :: Integer -> Integer
reduceByNextPrime n = reduce n (firstPrimeFactor n)
where reduce num div =
if mod num div /= 0
then num
else reduce (quot num div) div
euler3 :: Integer -> Integer
euler3 n =
if reduced == 1
then n
else euler3' reduced
where reduced = reduceByNextPrime n