# How to FInd the sum of odd divisor of a number in Mathematica?

So I want to find the sum of odd divisors of a number raised to some power. $$i.e.$$ I want to find $$\sum_{n=1}^\infty\sigma'_{-2k-1}(n)$$ where $$\sigma'_{-2k-1}(n) = \sum_{d|n, \text{d odd}} d^{-2k-1}$$.

How should I go with this? Using DivisorSigma[k,n] just sums up over all the divisors.

Any help is highly appreciated.

• Does it help if you remove all powers of 2from your number and sum the full set of divisors? Jun 9, 2021 at 13:37
• For the infinite sum, since $1$ is an odd divisor of all $n$ and $1^{-2k-1}=1$, the sum diverges, no? Jun 9, 2021 at 13:37
• You could just brute force it. Find the divisors, filter out the odds, raise them to the -(2*k+1)th and total: Total[Select[Divisors[n],OddQ]^(-2*k-1)] Probably something more clever out there. Jun 9, 2021 at 14:53
• @MichaelE2 Yes, you are right. There is some exponential terms as well with very high negative powers which I have not written here. I am mainly interested to know how can I write code for this sum in mathematica. Jun 9, 2021 at 16:35
• DivisorSigmaPrime[r_, n_Integer] := DivisorSigma[r, NestWhile[#/2 &, n, EvenQ]] will get you $\sigma_r(n)$. Then Sum[] can be used for the summation. Jun 9, 2021 at 16:42

You could find the sum of odd divisors of a number raised to some power in the following way:

DivisorSum[n, #^(-2k-1) &, OddQ]


You can then use Sum[ ] for summation.

• DivisorSum[] is indeed the appropriate tool to use here. Jun 10, 2021 at 2:05

To incorporate comments, for the sake of completeness: Of the three current suggestions in the comments and answer, Daniel Lichtblau's is fastest:

DivisorSigmaPrime // ClearAll;
DivisorSigmaPrime[r_, n_Integer] :=
DivisorSigma[r, NestWhile[#/2 &, n, EvenQ]];


It's literally a divide-and-conquer approach, as dividing out twos removes the even divisors.

k = 2;
Table[Total[Select[Divisors[n], OddQ]^(-2*k - 1)], {n, 10000}]; // AbsoluteTiming
Table[DivisorSum[n, #^(-2 k - 1) &, OddQ], {n, 10000}]; // AbsoluteTiming
Table[DivisorSigmaPrime[-2 k - 1, n], {n, 10000}]; // AbsoluteTiming
Clear[n, k];
(*
{0.253292, Null}  -- @Lusine
{0.172394, Null}  -- @N.J.Evans
{0.108652, Null}  -- @Daniel
*)


The differences are greater the more factors there are.

(* no even divisors *)
SeedRandom[0];
k = 2;
n = 2^0 Apply[Times]@Prime[RandomInteger[{10, 1000}, 10]];
DivisorSum[n, #^(-2 k - 1) &, OddQ] - 1 // RepeatedTiming // N[#, 20] &
Total[Select[Divisors[n], OddQ]^(-2*k - 1)] - 1 // RepeatedTiming // N[#, 20] &
DivisorSigmaPrime[-2 k - 1, n] - 1 // RepeatedTiming // N[#, 20] &
Clear[n, k];
(*
{0.00940233,   1.4631160740223029704*10^-13}  -- @Lusine
{0.00823647,   1.4631160740223029704*10^-13}  -- @N.J.Evans
{0.0000936843, 1.4631160740223029704*10^-13}  -- @Daniel
*)

(* many even divisors *)
SeedRandom[0];
k = 2;
n = 2^20 Apply[Times]@Prime[RandomInteger[{10, 1000}, 10]];
DivisorSum[n, #^(-2 k - 1) &, OddQ] - 1 // RepeatedTiming // N[#, 20] &
Total[Select[Divisors[n], OddQ]^(-2*k - 1)] - 1 // RepeatedTiming // N[#, 20] &
DivisorSigmaPrime[-2 k - 1, n] - 1 // RepeatedTiming // N[#, 20] &
Clear[n, k];
(*
{0.0259015,   1.4631160740223029704*10^-13}  -- @Lusine
{0.023558,    1.4631160740223029704*10^-13}  -- @N.J.Evans
{0.000116666, 1.4631160740223029704*10^-13}  -- @Daniel
*)


I didn't find much variation in relative timings if k is changed. (Large n and k leads to lots of bigInt calculations, and all three methods slow down.)