var
f: array[1..100000] of longint;
a, b, n, i: longint;
p, q, k, j: longint;
flag: boolean;
begin
assign(input, 'sequenceb.in'); reset(input);
assign(output, 'sequenceb.out'); rewrite(output);
read(a, b, n);
f[1] := 1; f[2] := 1;
flag := true; i := 3;
while flag do
begin
f[i] := (a * f[i - 1] + b * f[i - 2]) mod 7;
if i mod 2 = 0 then
begin
p := 1; q := i div 2 + 1;
for j := 1 to i div 2 do
if f[p] = f[q] then
begin
inc(p); inc(q);
end else break;
dec(p);
if p = i div 2 then
begin
k := p; flag := false;
end;
end;
inc(i);
end;
write(f[(n - 1) mod k + 1]);
close(input); close(output);
end.