Little P has just learned the shell-sort sorting algorithm. He was given some code that sorts an array of N integers in ascending order. Let A be the array to be sorted.
where i, N, X, gap, temp, ok are integers (int for C/C++).
While typing this code, little P forgot to copy line 11.
You are given the array to be sorted, A. A has N distinct elements, all between 1 and N.
You are asked to find all the values X for which the algorithm (without line 11) sorts A. We call these X values to be valid.