背公式的题,毫无意义
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
#define N 20005
using namespace std;
int h[N];
int ok(int x)
{
if(x == 1)return 0;
for(int i = 2;i*i<=x;i++)
if(x%i == 0)return 0;
return 1;
}
int main()
{
int n,m,i,j,x;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(h,0,sizeof(h));
while(!ok(n))n++;
for(i = 0;i<m;i++)
{
scanf("%d",&x);
int p = x%n,f = 0;
for(j = 0;j<n;j++)
{
if(!h[(p+j*j)%n])
{
h[(p+j*j)%n] = f = 1;
printf("%d",(p+j*j)%n);
break;
}
}
if(!f)printf("-");
if(i!=m-1)printf(" ");
}
printf("\n");
}
return 0;
}