I want a closed form for the sum $$S=\sum_{k=0}^n a^k \left\lfloor\frac{k}{p}\right\rfloor$$ where: $a\ne 1<p<n;\quad p\in\mathbb Z$
I know a related identity,
$$\quad\displaystyle \sum_{k=0}^n\left\lfloor\frac{k}{p}\right\rfloor=\left(n+1-\frac{p}{2}\right)\left\lfloor\frac{n}{p}\right\rfloor-\frac{p}{2}\left\lfloor\frac{n}{p}\right\rfloor^2\quad\;,$$
but I can't apply it to this problem!
Result for this sum:
$$\quad\displaystyle S=\dfrac{a^{n+1}}{a-1}\left\lfloor\frac{n+1}{p}\right\rfloor-\dfrac{a^p\left(a^{p\left\lfloor\frac{n+1}{p}\right\rfloor}-1\right)}{(a-1)(a^p-1)}$$
Can you prove it?