测试点4
二次方探查:仅向正方向,即+11,+22,+3*3……
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 10010;
bool p[maxn] = { 0 };
int x[maxn] = { 0 };
void Init() {
p[1] = true;
for (int i = 2; i < maxn; i++)
{
for (int j = i+i; j < maxn; j+=i)
{
p[j] = true;
}
}
}
int main(){
int msize,n;
Init();
cin >> msize >> n;
while (p[msize] != false)msize++;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
if (x[a%msize]==0)
{
cout << a % msize;
x[a%msize] = 1;
}
else
{
int m = 1,flag=0;
while (m<msize)
{
if (x[(a+m*m)%msize]==0)
{
x[(a + m * m) % msize] = 1;
break;
}
m++;
}if(m==msize)
cout << '-';
else cout << (a + m * m) % msize;
}if (i!=n-1)
{
cout << ' ';
}
}
return 0;
}