1078. Hashing (25)

传送门:https://www.patest.cn/contests/pat-a-practise/1078

一开始没有读懂二次探测的意思,导致一个WA,后来参考了别人的代码发现少了二次探测的过程.加上后顺利AC h(x) = (hash(x)+j*j)%Tsize; Hash(x) = x%Tsize;

AC代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
bool IsPrime(int n){
    if(n==1)
        return false;
    for (int i=2; i<=sqrt(n); ++i) {
        if(n%i==0)
            return false;
    }
    return true;
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    if(!IsPrime(n)){
        for (int i=n+1;; ++i) {
            if(IsPrime(i)){
                n = i;
                break;
            }
        }
    }
    vectorans(n,false);
    for (int i=0; i


你可能感兴趣的:(PAT解题报告)