#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<=100;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<=100;i++)
s[i]=f[i]*10+f[i+1];
int t=100;
for (i=1;i<=99;i++)
for (j=i+1;j<=99;j++)
{
if (s[i]==s[j]){
t=j-i;
if (t==1)
ans=0;
}
}
f[0]=f[t];
ans=n-n/t*t;
ans=f[ans];
printf("%d",ans);
}