Difference between revisions of "99 questions/Solutions/37"

From HaskellWiki
Jump to navigation Jump to search
(No difference)

Revision as of 16:57, 13 July 2010

(**) Calculate Euler's totient function phi(m) (improved).

Given prime_factors_mult from problem 36, we get

totient m = product [(p - 1) * p ^ (c - 1) | (p, c) <- prime_factors_mult m]

This just uses a list comprehension to build each term of the product in the formula for phi, then multiplies them all.