-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1078.cpp
61 lines (57 loc) · 1.19 KB
/
1078.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
50
51
52
53
54
55
56
57
58
59
60
61
//
// 1078.cpp
// 算法
//
// Created by 王怡凡 on 2017/8/24.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include <stdio.h>
#include<cmath>
using namespace std;
const int maxn = 10010;
int Msize,n;
bool hashes[maxn] = {false};
bool isPrime(int x) {
if(x<=1) return false;
int sqr = int(sqrt(x*1.0));
int i;
for(i=2;i<=sqr;i++) {
if(x%i==0) {
return false;
}
}
return true;
}
int main(){
scanf("%d %d",&Msize,&n);
int i,num;
while(!isPrime(Msize)) {
Msize++;
}
for(i=0;i<n;i++) {
scanf("%d",&num);
int M = num%Msize;
if(hashes[M]==false) {
printf("%d",M);
hashes[M] = true;
} else {
bool flag = false;
for(int j=1;j<Msize;j++) {
M = (num+j*j)%Msize;
if(hashes[M]==false) {
printf("%d",M%Msize);
hashes[M] = true;
flag = true;
break;
}
}
if(!flag) {
printf("-");
}
}
if(i!=n-1) {
printf(" ");
}
}
return 0;
}