# Solving $key=(\sum_{K=0}^n\frac{1}{a^K})\mod m$ with High limits

I was solving this equation:- $$key=(\sum_{K=0}^n\frac{1}{a^K})\mod m$$

### Given

$$1,000,000,000 < a, n, m \; < 5,000,000,000$$ $$a, m \; are \;coprime$$

I solved it bruteforcely but it won't work in the given constrains so I need a faster algorithm or is there is something I can notice to make the formula easier to solve ?

-