I am writing a program in which I want to make changes to make it more efficient.
What the program does is it takes three inputs $m$, $n$ and $x$ and I have to find the value of the following equation: $$ 1^n+ 2^n+\cdots + m^n \mod{x} $$
Is there a better way than calculating the whole value and then solving for answer? Because if $n$ and $m$ are large it takes a lot of computation time which I am trying to avoid.