[String] --hash

Until today, I did not know the hash is written.


For a string c, we can hash it out, get a different value.

definition

 

typedef unsigned long long ull;
const int N=4e5+10;
char c[N];
ull h[N],g[N];
void hash(){
    g[0]=1;
    for(int i=1;c[i];i++){
        h[i]=h[i-1]*131+c[i];
        g[i]=g[i-1]*131;
    }
}

Then its substring , where p is a prime number.

wool tt = h [len] -h [len i] * g [i];

Ull use nature is greater than the upper limit of the number of modulo is automatically to achieve the purpose of the hash.

 

Guess you like

Origin www.cnblogs.com/Nelson992770019/p/11354257.html