#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
bool isprime(int x){
for(int i=2;i*i<=x;i++){
if(x%i==0) return false;
}
if(x==0 || x==1) return false;
else
return true;
}
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif // LOCAL
bool h[101000]={false};
int n,m;
cin>>n>>m;
int k=n+1;
if(!isprime(n)){
while(!isprime(k)) k++;
}else k=n;
for(int i=0;i<m;i++){
int x;
cin>>x;
int pos=x%k;
if(h[pos]==false){ cout<<pos;h[pos]=true; }
else{
int d=1;
while(h[(pos+d*d)%k]){
d++;
if(d>k) break;
}
if(h[(pos+d*d)%k]==false){
cout<<(pos+d*d)%k;h[(pos+d*d)%k]=true;
}else cout<<"-";
}
if(i!=m-1) cout<<" ";
}
return 0;
}
【PAT】1078. Hashing
最新推荐文章于 2022-10-24 20:19:07 发布