#include<cstdio>#include<cmath>constint nmax =20000;bool prime[nmax];boolisPrime(int x);intNextPrime(int x);intmain(){int n, m, temp, j;scanf("%d%d",&n,&m);if(!isPrime(n)) n =NextPrime(n);for(int i =0; i < m; i++){if(i)printf(" ");scanf("%d",&temp);if(prime[temp%n]==false){
prime[temp%n]=true;printf("%d", temp%n);}else{for(j =1; j <= n; j++){int p =(temp%n + j*j)% n;if(prime[p]==false){
prime[p]=true;printf("%d", p);break;}}if(j == n +1)printf("-");}}return0;}boolisPrime(int x){if(x <=1)returnfalse;for(int i =2; i <=sqrt(x); i++)if(x % i ==0)returnfalse;returntrue;}intNextPrime(int x){int n = x +1;while(1){if(isPrime(n))return n;else n++;}}
1078 Hashing解题代码测试结果问题整理解题代码#include<cstdio>#include<cmath>const int nmax = 20000;bool prime[nmax];bool isPrime(int x);int NextPrime(int x);int main() { int n, m, temp, j; scanf("%d%d", &n, &m); if (!isPrime(n)) n = NextPrime