login
a(n) is the sum of all the remainders when n is divided by positive integers less than n/2 and coprime to n.
5

%I #18 Mar 18 2021 15:44:07

%S 0,0,0,0,1,0,2,2,2,1,7,2,7,6,5,4,15,7,19,10,9,8,32,9,20,20,28,13,46,

%T 14,47,31,27,31,48,17,62,39,58,26,87,26,94,53,52,41,127,48,100,65,79,

%U 61,154,52,105,62,90,80,200,45,180,113,138,103,162,77,229,116,149,73,274,87,257,166,178

%N a(n) is the sum of all the remainders when n is divided by positive integers less than n/2 and coprime to n.

%H Robert Israel, <a href="/A340740/b340740.txt">Table of n, a(n) for n = 1..10000</a>

%F a(n) = Sum_{k=1..floor((n-1)/2)} (n mod k) * floor(1/gcd(n,k)). - _Wesley Ivan Hurt_, Jan 18 2021

%e For n = 11, a(11) = (11 mod 1)+(11 mod 2)+(11 mod 3)+(11 mod 4)+(11 mod 5) = 7.

%p f:= proc(n) local k;

%p add(`if`(igcd(k,n)=1, n mod k, 0),k=1..floor(n/2))

%p end proc:

%p map(f, [$1..100]);

%t Table[Sum[Mod[n, i]*Floor[1/GCD[i, n]], {i, Floor[(n - 1)/2]}], {n,

%t 100}] (* _Wesley Ivan Hurt_, Jan 18 2021 *)

%o (PARI) a(n) = sum(k=1, n\2, if (gcd(k, n)==1, n%k)); \\ _Michel Marcus_, Jan 18 2021

%o (Python)

%o from math import gcd

%o def A340740(n): return sum(n % k for k in range(1,n//2+1) if gcd(k,n) == 1) # _Chai Wah Wu_, Mar 18 2021

%Y Cf. A067439.

%K nonn,look

%O 1,7

%A _J. M. Bergot_ and _Robert Israel_, Jan 18 2021