Ruby, 87 66 80 75 70 68 bytes
This answer is based on Luis Mendo's MATL answerLuis Mendo's MATL answer, wythagoras's Python answerwythagoras's Python answer, and the idea that the arithmetic derivative of a number m
is equal to m·(1/p1 + 1/p2 + ... + 1/pn)
where p1...pn
is every prime factor of n
to multiplicity.
->n{s=0;(2...m=n.abs).map{|d|(m/=d;s+=n/d)while m%d<1};m<2?0:s+0**s}
This function is called in the following way:
> a=->n{s=0;(2...m=n.abs).map{|d|(m/=d;s+=n/d)while m%d<1};m<2?0:s+0**s}
> a[299792458]
196831491
Ungolfing:
def a(n)
s = 0
m = n.abs
(2...m).each do |z|
while m%d == 0
m /= d
s += n / d
end
end
if s == 0
if n > 1
s += 1 # if s is 0, either n is prime and the while loop added nothing, so add 1
# or n.abs < 2, so return 0 anyway
# 0**s is used in the code because it returns 1 if s == 0 and 0 for all other s
end
end
return s
end