-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashing.cpp
49 lines (46 loc) · 881 Bytes
/
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
49
#include <iostream>
int hah[10010] = {0};
bool isprime(int n)
{
if (n == 1)
return false;
for (int i = 2; i < n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
int main()
{
int m, n;
std::cin >> m >> n;
while (true)
{
if (isprime(m))
break;
m++;
}
for (int i = 0; i < n; i++)
{
int position, temp;
int flag = 0;
std::cin >> temp;
for (int j = 0; j < m; j++)
{
position = (temp + j * j) % m;
if (hah[position] == 0)
{
std::cout << position;
hah[position] = 1;
flag = 1;
break;
}
}
if (flag == 0)
std::cout << "-";
if (i < n - 1)
std::cout << " ";
}
return 0;
}