Skip to content

Instantly share code, notes, and snippets.

@rebornwwp
Last active July 23, 2018 15:28
Show Gist options
  • Save rebornwwp/7f0f1a2c88f9182102c0a43221a60348 to your computer and use it in GitHub Desktop.
Save rebornwwp/7f0f1a2c88f9182102c0a43221a60348 to your computer and use it in GitHub Desktop.
将一个数分解成多个素数的乘积
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