use std::io; fn matmul(X: &Vec>, Y: &Vec>, N: usize) -> Vec> { let mut Z = vec![vec![0; N]; N]; for i in 0..N { for j in 0..N { for k in 0..N { Z[i][j] ^= X[i][k] * Y[k][j]; // XOR 演算 } } } Z } fn matpow(X: &Vec>, k: i32, N: usize) -> Vec> { let mut I = vec![vec![0; N]; N]; for i in 0..N { I[i][i] = 1; // 単位行列 } if k == 0 { return I; } else if k == 1 { return X.clone(); } if k % 2 == 0 { let half_pow = matpow(X, k / 2, N); return matmul(&half_pow, &half_pow, N); } else { let half_pow = matpow(X, (k - 1) / 2, N); let Y = matmul(&half_pow, &half_pow, N); return matmul(X, &Y, N); } } fn main() { let mut input = String::new(); io::stdin().read_line(&mut input).expect("Failed to read line"); let mut input_iter = input.split_whitespace(); let N: usize = input_iter.next().unwrap().parse().unwrap(); let K: i32 = input_iter.next().unwrap().parse().unwrap(); let mut A = vec![]; input.clear(); io::stdin().read_line(&mut input).expect("Failed to read line"); for num in input.split_whitespace() { A.push(num.parse::().unwrap()); } let T = N + 1; let M = (K - 1) % T as i32; let mut A1 = vec![vec![0; N]; N]; // A1行列の初期化 for i in 0..(N - 1) { A1[i][i + 1] = 1; } for j in 0..N { A1[N - 1][j] = 1; } // A1をM回累乗した行列を計算 let B = matpow(&A1, M, N); // 答えを計算 let mut ans = 0; for i in 0..N { ans ^= B[0][i] * A[i]; } println!("{}", ans); }