a, b, N = map(int, input().split()) M = 10**9 + 7 RA = RD = 1; RB = RC = 0 XA = a; XB = b; XC = 1; XD = 0 while N: if N & 1: RA, RB, RC, RD = (RA*XA + RB*XC) % M, (RA*XB + RB*XD) % M, (RC*XA + RD*XC) % M, (RC*XB + RD*XD) % M XA, XB, XC, XD = (XA**2 + XB*XC) % M, XB*(XA + XD) % M, XC*(XA + XD) % M, (XB*XC + XD**2) % M N >>= 1 print(RC)