F=[0,0,0] F[0],F[1],N=map(int,raw_input().split()) F[2]=F[0]^F[1] print F[N%3]