import java.util.*; import java.io.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); int a = Integer.parseInt(first[0]); int b = Integer.parseInt(first[1]); int n = Integer.parseInt(first[2]); long[][] xy = new long[31][4]; xy[0] = new long[]{a, b, 1, 0}; for (int i = 1; i < 31; i++) { xy[i][0] = (xy[i - 1][0] * xy[i - 1][0] + xy[i - 1][1] * xy[i - 1][2]) % MOD; xy[i][1] = (xy[i - 1][0] * xy[i - 1][1] + xy[i - 1][1] * xy[i - 1][3]) % MOD; xy[i][2] = (xy[i - 1][2] * xy[i - 1][0] + xy[i - 1][3] * xy[i - 1][2]) % MOD; xy[i][3] = (xy[i - 1][2] * xy[i - 1][1] + xy[i - 1][3] * xy[i - 1][3]) % MOD; } long x = 1; long y = 0; for (int i = 30; i >= 0 && n > 0; i--) { if (n >= (1 << i)) { n -= (1 << i); long xx = (x * xy[i][0] + y * xy[i][1]) % MOD; long yy = (x * xy[i][2] + y * xy[i][3]) % MOD; x = xx; y = yy; } } System.out.println(y); } }