class A def initialize f0, f1, n = gets.chomp.split(' ').map(&:to_i) f0 = "%019b" % [f0] f1 = "%019b" % [f1] answer = "" 18.downto(0) do |index| ch1 = f0[index] ch2 = f1[index] if ch1 == '0' && ch2 == '0' answer << '0' elsif ch1 == '0' && ch2 == '1' answer << ['1','0','1'][(n-2)%3] elsif ch1 == '1' && ch2 == '0' answer << ['1','1','0'][(n-2)%3] else answer << ['0','1','1'][(n-2)%3] end end if n == 0 puts f0.to_i(2) elsif n == 1 puts f1.to_i(2) else puts answer.reverse.to_i(2) end end end A.new