#include<iostream>
#include<cstdio>
using namespace std;
int a,b,n;
int f[10002]={0};
int main()
{
freopen("sequenceb.in","r",stdin);
freopen("sequenceb.out","w",stdout);
int i,j,k,l;
f[1]=1;
f[2]=1;
cin>>a>>b>>n;
k=0;
i=2;
for (i=3;i<=10000;i++)
f[i]=(a*f[i-1]+b*f[i-2])%7;
k=1;
int t;
for (i=3;i<=10000;i++)
{
if ((f[i]==1)&&(f[i+1]==1)&&(k==1))
{
for (j=1;j<i;j++)
if (f[j]!=f[j+i-1])
k=0;
if (k==1)
{
t=i-1;
i=10001;
}
}
}
n%=t;
if (n==0) n=t;
cout<<f[n]<<endl;
return 0;
}