P23696 [AtCoder] [ABC009D] Recurrence Formula
提高
题目描述

Problem Description

The sequence $ A $ consists of elements that can be represented as 32-bit unsigned integers, and its values are determined as follows:

  • The first $ K $ terms $ A_1, A_2, ..., A_K $ are given as input.
  • Separately, a sequence of $ K $ terms $ C_1, C_2, ..., C_K $ (all elements of which also fit within 32-bit unsigned integers) is given as input, and the values of $ A $ from the $ K+1 $ term onwards are calculated using $ C $ as follows:
  • For $ N ≧ 1 $, $A_{N+K} = (C_1 \, \text{AND} \, A_{N+K-1}) \, \text{XOR} \, (C_2 \, \text{AND} \, A_{N+K-2}) \, \text{XOR} \, ... \, \text{XOR} \, (C_K \, \text{AND} \, A_N)$
  • Here, AND denotes the bitwise AND operation, and XOR denotes the bitwise XOR operation.

Write a program to find the $ M $th value $ A_M $ of the sequence $ A $.

Input Format

Input is given from the standard input in the following format:

$ K $ $ M $ $ A_1 $ $ A_2 $ $ ... $ $ A_K $ $ C_1 $ $ C_2 $ $ ... $ $ C_K $

  • The first line contains the integer $ K $ ( $ 1 ≦ K ≦ 100 $ ), representing the number of initially determined terms, and the integer $ M $ ( $ 1 ≦ M ≦ 10^9 $ ), representing the term number to find in the sequence.
  • The second line contains the first $ K $ terms of the sequence $ A $, all of which fit within 32-bit unsigned integers.
  • The third line contains the $ K $ terms of the sequence $ C $, used to calculate the subsequent terms of $ A $, all of which also fit within 32-bit unsigned integers.

Output Format

Output the value of $ A_M $ on a single line.

Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

3 5
10 20 30
7 19 13

Sample Output #1

16

Sample Input #2

5 100
2345678901 1001001001 3333333333 3141592653 1234567890
2147483648 2147483647 4294967295 4294967294 3434343434

Sample Output #2

1067078691

Sample Input #3

30 999999999
11627 5078 8394 6412 10346 3086 3933 668 9879 11739 4501 6108 12336 8771 2768 2438 2153 7047 5476 313 1264 369 12070 10743 10663 747 370 4671 5235 3439
114 3613 3271 5032 11241 6961 3628 150 12191 2396 7638 3046 11594 8162 11136 786 9878 2356 11660 1070 3649 10882 9746 1415 3307 7077 9319 9981 3437 544

Sample Output #3

2148

Notes/Hints

Sample Explanation 1

Calculating the values of $ A $ step by step yields the following:
- $A_4 = (7 \, \text{AND} \, 30) \, \text{XOR} \, (19 \, \text{AND} \, 20) \, \text{XOR} \, (13 \, \text{AND} \, 10) = 30$
- $A_5 = (7 \, \text{AND} \, 30) \, \text{XOR} \, (19 \, \text{AND} \, 30) \, \text{XOR} \, (13 \, \text{AND} \, 20) = 16$

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 5 10 20 30 7 19 13
样例输出
16