J, 149 bytes
*[:*/1(-1%~~:)&.@qq:
Instead of using the gcd formula, I useThis is based on the product formula
Formula http://i.imgur.com/MX9dJQS.pngJsoftware's essay on totient functions.
Given n = p1e1 ∙ p2e2 ∙∙∙ pkek where p iterates over eachk is a prime factor of the distinct primes that divide n, the totient function φ(n) = φ(p1e1) ∙ φ(p2e2) ∙∙∙ φ(pkek) = (p1 - 1) p1e1 - 1 ∙ (p2 - 1) p2e2 - 1 ∙∙∙ (pk - 1) pkek - 1.
Usage
Note: Extra commands used for formatting multiple input/output.
f =: *[:*/1(-1%~~:)&.@qq:
(,.f"0) 1 2 3 8 9 26 44 105
1 1
2 1
3 2
8 4
9 6
26 12
44 20
105 48
f 12345
6576
Explanation
*[:*/1(-1%~~:)&.@qq: Input: integer n
q: Prime decomposition. Get the prime factors of n
whose product is n
( ~.@ )& Get only theOperate distincton valuesthem
in that~: list
1% Nub-sieve. Create a mask where 1 Computeis the reciprocal for eachfirst primeoccurrence
1- of Subtracta eachunique primevalue reciprocaland from0 1elsewhere
[:*/ - Reduce theSubtract listelementwise usingbetween multiplication
*the prime factors and the mask
&.q: Perform the inverse Multiplyof thatprime productdecomposition by(Product nof andthe returnvalues)