#J, 30 27 19 chars#
J, 30 27 19 chars
Thanks to @Dennis for chopping off 3 characters.
Thanks to @Zgarb for chopping off 8 characters.
0:`(*[:+/%@q:@|)@.*
Sample input:
0:`(*[:+/%@q:@|)@.* _8
_12
0:`(*[:+/%@q:@|)@.* 0
0
0:`(*[:+/%@q:@|)@.* 8
12
How it works:
0:`(*[:+/%@q:@|)@.* N
XX`[email protected] if Z then Y else X end
0: X: return 0
Z Z: signum(N)
(*[:+/%@q:@|) Y: N*add_all(reciprocal_all(all_prime_factors(abs(N))))
N
* *
[:+/ add_all( )
%@ reciprocal_all( )
q:@ all_prime_factors( )
| abs( )
N