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 \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)
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