Calculate your initial hash for the haystack, then roll the hash to the next character. Compare the resulting hash with the result of calling compute_hash(haystack.substr(1, needle_length)) - they should be the same right? They are the same when the prime is 7. but they’re not when using a bigger prime.
I think the mod is kicking in, which then means you can’t just divide the first character out of the hash.
substring_hash = compute_hash(haystack.substr(0, needle_length));
int i = 1;
substring_hash = rolling_hash(haystack.substr(i - 1, needle_length), substring_hash, haystack[i + needle_length - 1]);
cout << substring_hash << "\n";
cout << compute_hash(haystack.substr(1, needle_length)) << "\n";