sum d p^k, k=0 to n