#include using namespace std; int mod = 1000000007; vector> Mul(vector> A,vector> B) { vector>ans(A.size(),vector(A.size())); for(int i = 0; i < A.size(); i++) { for(int j = 0; j < A.size(); j++) { for(int k = 0; k < A.size(); k++) { ans[i][j] += A[i][k]*B[k][j]%mod; ans[i][j] %= mod; } } } return ans; } vector> Pow(vector> A,long long B) { vector>ans(A.size(),vector(A.size())); for(int i = 0; i < A.size(); i++) { ans[i][i] = 1; } while (B) { if(1 & B) { ans = Mul(ans,A); } A = Mul(A,A); B /= 2; } return ans; } int main() { int a,b,n; cin >> a >> b >> n; vector>tmp(2,vector(2)); tmp[0][0] = a; tmp[0][1] = b; tmp[1][0] = 1; tmp = Pow(tmp,n); cout << tmp[1][0] << endl; }