#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
int s[1000];
int n,i,j,a,b,ans;
int f[1000];
int main()
{
freopen("sequenceb.in","r",stdin);
freopen("sequenceb.out","w",stdout);
scanf("%d%d%d",&a,&b,&n);
f[1]=1;
f[2]=1;
for (i=3;i<=n;i++){
f[i]=(a*f[i-1]+b*f[i-2])%7;
}
if (n<=100){
printf("%d",f[n]);
return 0;
}
for (i=1;i<=n;i++)
s[i]=s[i]*10+s[i+1];
int t=100;
for (i=1;i<=n;i++)
for (j=i+1;j<=n;j++)
{
if (s[i]==s[j] && (j-i)<t){
t=j-i;
}
}
ans=n-n/t*t;
ans=f[n];
printf("%d",ans);
}