![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0b067563888de066ef7513bc376aba3e.png)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int N = 10001;
bool hashtable[N] = { 0 };
bool isprime(int n) {
if (n <= 1) return false;
int sqr = sqrt(n);
for (int i = 2; i <= sqr; i++) {
if (n % i == 0)
return false;
}
return true;
}
int main()
{
int n, Tsize, a;
cin >> Tsize >> n;
while (isprime(Tsize) == false)
Tsize++;
for (int i = 0; i < n; i++)
{
cin >> a;
int M = a % Tsize;
if (hashtable[M] == false)
{
hashtable[M] = true;
if (i == 0) cout << M;
else cout << " " << M;
}
else
{
int step;
for (step = 1; step < Tsize; step++)
{
M = (a + step * step) % Tsize;
if (hashtable[M] == false)
{
hashtable[M] = true;
if (i == 0) cout << M;
else cout << " " << M;
break;
}
}
if (step == Tsize)
{
if (i > 0)
cout << " " << "-";
}
}
}
}