#include #define rep(i,a,b) for(int i=int(a);i> A >> R >> N; A %= MOD, R %= MOD; if(R == 1){ cout << A * (N % MOD) % MOD << endl; }else if(R == 0){ cout << 0 << endl; }else{ cout << (A * R) % MOD * (divmod( (powmod(R,N) - 1) , R - 1)) % MOD << endl; } }