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.)
Total[Select[Divisors[n],OddQ]^(-2*k-1)]
Probably something more clever out there. $\endgroup$DivisorSigmaPrime[r_, n_Integer] := DivisorSigma[r, NestWhile[#/2 &, n, EvenQ]]
will get you $\sigma_r(n)$. ThenSum[]
can be used for the summation. $\endgroup$