why there is need to add mod;
for(int i=0;i+m<=n;i++){
int newhash=pref[i-m+1];
if(i-1>0){
newhash-=pref[i-1];
newhash+=mod;
newhash%=mod;
if(newhash==(pat_hash*power(p,i))%mod){
cout<<i<<endl;
}
}
}
why there is need to add mod;
for(int i=0;i+m<=n;i++){
int newhash=pref[i-m+1];
if(i-1>0){
newhash-=pref[i-1];
newhash+=mod;
newhash%=mod;
if(newhash==(pat_hash*power(p,i))%mod){
cout<<i<<endl;
}
}
}
hi… so basically we add mod to avoid the result becoming negative… thats all
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.