0

Given $n$, $a$ and $b$, find most efficient way to compute

$S(n, a, b) = \sum_{i=1}^n a^i i^b$

Most trivial way would be $O(n\cdot(n+b))$.

If we use fast exponentiation then it would be $O(n\cdot(\log n+\log b))$

I am looking for lot better, possibly all logarithmic factors.

Following up from @Integrand's comments I realised this might be the general case of any of these closed formula:

$\sum_{i=1}^ni3^i$

$\sum\limits_{i=1}^{n}ip^i$

$\sum \limits_{r=1}^d r \cdot 2^r$

But my gut feeling says there should be recurrence relation to compute Matrix exponentiation.

As brought up by @metamorphy , a,b,n are 64 bit integers and I need all the results under mod 10^9+7(ie a 32 bit prime)

  • Avoid the use of $*$ to denote multiplication. – jjagmath Jul 21 '22 at 22:55
  • There should be an closed form using derivatives, Stirling numbers, and the geometric series. – Integrand Jul 21 '22 at 23:09
  • @Integrand I found closed formula for $\sum_{i=1}^n\ a^i.i$. Updated the question with links , but seems $i^b$ will need further treatment – ishandutta2007 Jul 22 '22 at 02:25
  • 2
    The computation model is unclear. What is $a$? (Are you working with integers, or rational numbers, or modular arithmetic, or what?) Which operations are allowed, and how the complexity is counted? (Say, if you're working with integers and counting bit operations, then your complexity of using fast exponentiation doesn't take into account the size of the integers involved.) A closed form of the sum exists, but it may lead to an inefficient algorithm (this is the case for modular arithmetic, say). – metamorphy Jul 22 '22 at 03:25
  • 1
    @metamorphy a,b,n are all 64 bit integers.. Good point to mention the modulo, I had missed that. yes I need results under modulo. ie modulo 10^9+7(ie a 32 bit prime). – ishandutta2007 Jul 22 '22 at 03:42
  • @metamorphy I am updating the question. can you mean while also share the closed but inefficient form that you were talking about. – ishandutta2007 Jul 22 '22 at 03:43

1 Answers1

2

Discarding the problem of time complexity and the modulo, for any kind of numbers $(a,b)$ $$S(n, a, b) = \sum_{i=1}^n a^i\, i^b=\text{Li}_{-b}(a)-a^{n+1}\, \Phi (a,-b,n+1)$$ where appear the polylogarithm function and the Lerch transcendent function.

For both of them, there are very efficient algorithms available.