通过打表找出规律
打表代码
#include<bits/stdc++.h>
using namespace std;
bool vis[20];
int a[20];
void f(int x)
{
printf("Case: %d\n",x);
for(int i=0;i<x;i++)
a[i]=i;
int res=0;
while(1)
{
int now=0,tot=1;
memset(vis,false,sizeof(vis));
vis[0]=true;
while(!vis[(now+a[now])%x])
{
now=(now+a[now])%x;
vis[now]=true;
tot++;
}
if(tot==x)
{
res++;
for(int i=0;i<x;i++)
printf(i==x-1?"%d\n":"%d ",a[i]);
}
if(!next_permutation(a,a+x)) break;
}
printf("%d\n",res);
}
int main()
{
for(int i=1;i<=10;i++)
f(i);
}