OFFSET
0,3
COMMENTS
The case n = 0 is well defined because zero divides zero. When implementing the sequence it is advisable to use the definition of divisibility of an integer directly and not the set of divisors, because this is infinite in the case n = 0 and, therefore, cannot be represented in computer algebra systems, which leads to a wide variety of error messages depending on the system. Some of these error messages are in turn incorrect, because the test of divisibility by zero does not involve division and therefore should not lead to a 'ZeroDivisionError' or similar.
REFERENCES
Tom M. Apostol, Introduction to Analytic Number Theory, Springer 1976, p. 14.
FORMULA
MAPLE
MATHEMATICA
a[n_]:=n+Sum[k*Boole[!Divisible[n, n-k]], {k, 0, n-1}]; Array[a, 55, 0] (* Stefano Spezia, Nov 15 2023 *)
PROG
(SageMath)
def A367368(n): return sum(k for k in (0..n) if not (n - k).divides(n))
print([A367368(n) for n in range(55)])
(Julia)
using AbstractAlgebra
function A367326(n) sum(k for k in 0:n if ! is_divisible_by(n, n - k)) end
[A367326(n) for n in 0:54] |> println
(Python)
def divides(k, n): return k == n or ((k > 0) and (n % k == 0))
def A367368(n): return sum(k for k in range(n + 1) if not divides(n - k, n))
print([A367368(n) for n in range(55)])
(Python)
from math import prod
from sympy import factorint
def A367368(n):
f = factorint(n).items()
return (n*(n+1)>>1)-n*prod(e+1 for p, e in f)+prod((p**(e+1)-1)//(p-1) for p, e in f) if n else 0 # Chai Wah Wu, Nov 17 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Peter Luschny, Nov 15 2023
STATUS
approved