-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1078_Hashing.cpp
48 lines (44 loc) · 1.03 KB
/
1078_Hashing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
int isPrime(int x) {
if (x == 0 || x == 1) return false;
for (int i = 2; i * i <= x; ++i) {
if (x % i == 0) return false;
}
return true;
}
int main() {
int Msize, n;
cin >> Msize >> n;
while (!isPrime(Msize)) Msize++;
vector<int> occupied(Msize, 0);
vector<int> pos(Msize, -1);
int temp;
for (int i = 0; i < n; ++i) {
cin >> temp;
for (int j = 0; j < Msize; ++j) {
int index = (j * j + temp) % Msize;
if (!occupied[index]) {
pos[i] = index;
occupied[index] = 1;
break;
}
}
}
for (int i = 0; i < n; ++i) {
if (pos[i] != -1) {
if (i == 0)
cout << pos[i];
else
cout << " " << pos[i];
} else {
if (i == 0)
cout << "-";
else
cout << " "
<< "-";
}
}
cout << endl;
return 0;
}