1078 Hashing(25 分)
2018-09-07 本文已影响0人
zjh3029
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include<queue>
#include<string>
using namespace std;
vector<int> in, level;
#define C(X) cout<<X
#define ST system("pause")
#pragma warning(disable:4996)
int M, N, a;
vector<bool> v;
int isprime(int data)
{
if (data==1) data += 1;
for (int i = 2; i <(int)sqrt((int)data)+1; i++)
{
if (data%i==0)
{
data++;
i = 1;
}
}
return data;
}
string ins(int data,int b)
{
for (int i = 0; i < b-1; i++)
{
int temp = (data + i * i) % b;
if(v[temp]==false)
{
v[temp] = true;
return to_string(temp)+" ";
}
}
return "- ";
}
int main() {
cin >> M >> N;
M = isprime(M);
v.resize(M, false);
for (int i = 0; i < N; i++)
{
cin >> a;
string x=ins(a,M);
if (i!=N-1)
C(x);
else
{
x.erase(x.end() - 1, x.end());
C(x);
}
}
ST;
return 0;
}