```
public int CountArrangement(int N) {
bool[] visited = new bool[N + 1];
return Recurse(1, visited, N);
}
public int Recurse(int p, bool[] visited, int N) {
if (p > N) return 1;
int sum = 0;
for(int i = 1; i <= N; i++) {
if (visited[i] || (i % p != 0 && p % i != 0)) continue;
visited[i] = true;
sum += Recurse(p + 1, visited, N);
visited[i] = false;
}
return sum;
}
```