Sum of an eventually periodic sequence
ID: sum-of-an-eventually-periodic-sequence
Suppose a numerical sequence has period from index , and let . For with , split the required sum into complete periods and a tail of length . Every complete period contributes , proving the formula in the title. Precomputed prefix sums of one period make the tail lookup constant time. If this periodic sequence consists of the first differences of another sequence, the same formula extrapolates that original sequence by adding the initial value at .
New to topics? Read the docs here!