```
void dfs(int curr,int N,int used, int& res)
{
if(curr==N+1)
res++;
for(int i=1;i<=N;i++)
if(!(used&(1<<i))&&(!(i%curr)||!(curr%i)))
dfs(curr+1,N,used|(1<<i),res);
}
int countArrangement(int N)
{
int res=0;
dfs(1,N,0,res);
return res;
}
```