There are $N$ permutations $(a_1, a_2, \dots, a_{30})$ of $1, 2, \dots, 30$ such that for $m \in \{2,3,5\}$, $m$ divides $a_{n+m} - a_n$ for all integers $n$ with $1 \le n < n+m \le 30$. Find the remainder when $N$ is divided by 1000.
The conditions say that $a_n\bmod m$ depends only on $n\bmod m$, for $m=2,3,5$; so positions with a given residue mod $2$ get values in one residue class mod $2$, and so on.
Choose a permutation of the residues mod $2$, mod $3$ and mod $5$ ($2!\cdot3!\cdot5!$ ways); by the Chinese remainder theorem this fixes $a_n\bmod30$, hence $a_n$, for every $n$.
$N=2\cdot6\cdot120=1440$, remainder $440$. The answer is $\boxed{440}$.
There are $N$ permutations $(a_1, a_2, \dots, a_{42})$ of $1, 2, \dots, 42$ such that for $m \in \{2,3,7\}$, $m$ divides $a_{n+m} - a_n$ for all integers $n$ with $1 \le n < n+m \le 42$. Find the remainder when $N$ is divided by 1000.