PROBLEM LINK:
Author:Yuri Shilyaev
Tester:Hasan Jaddouh
Editorialist:Yury Shilyaev
DIFFICULTY:
Easy
PREREQUISITES:
Xor operation, constructive.
PROBLEM:
You are given two integers $N$ and $K$. Your task is to construct a sequence $g_1, \dots, g_N$, that $1 \le g_i \le K$ for all $i$ and $g_1 \oplus g_2 \oplus \cdots \oplus g_N$ is maximum possible.
QUICK EXPLANATION:
Let $m$ be the maximum integer that $2^m \le K$. The maximum possible answer is somewhere near $2^{m + 1} - 1$.
EXPLANATION:
Let's first print $2^m$ and $2^m - 1$. This numbers give xor $2^{m + 1} - 1$. Now, if let's complete the sequence with ones. The xor would not change if $N$ is even, otherwise, let's swap $2^m - 1$ we added with $2^m - 2$.
Of course, we should also consider some corner cases, on which our solution doesn't work. They are $N = 1; K = 1; K = 2; K = 3$.
AUTHOR'S AND TESTER'S SOLUTIONS:
Author's solution can be found here.
Tester's solution can be found here.