I am writing a program in which I want to make changes to make it more efficient.
whatWhat the program does is it takes three inputs m n$m$, $n$ and x$x$ and I have to find the value of the following equation: (1^n+ 2^n ... m^n )modulo x$$ 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$n$ and m$m$ are large it takes a lot of computation time which I am trying to avoid.