Last active
July 23, 2018 15:28
-
-
Save rebornwwp/7f0f1a2c88f9182102c0a43221a60348 to your computer and use it in GitHub Desktop.
将一个数分解成多个素数的乘积
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factors' :: Integral t => t -> [t] | |
factors' n | |
| n < 0 = factors' (-n) | |
| n > 0 = if 1 == n | |
then [] | |
else let fac = mfac n 2 in fac : factors' (n `div` fac) | |
where mfac m x | |
| rem m x == 0 = x | |
| x * x > m = m | |
| otherwise = mfac m (if odd x then x + 2 else x + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment