#include using namespace std; int main() { const long div = 1000000007; long a, b, n, prev = 0, current = 1; cin >> a >> b >> n; if (n < 2) { cout << n << endl; return 0; } for (int i = 2; i <= n; i++) { long next = (a * current % div + b * prev % div) % div; prev = current; current = next; } cout << current << endl; }