2025-06-24 20:57:55 +09:00

19 lines
325 B
C

#include <stdio.h>
int main() {
int l;
char s[51];
scanf("%d",&l);
scanf("%s",s);
long long hash = 0, ri = 1;
int m = 1234567891;
for(int i=0; s[i]!='\0'; i++) {
hash = (hash + (((s[i] - 'a' + 1)%m)*ri)%m)%m;
ri = (ri*31)%m;
}
printf("%lld\n",hash);
return 0;
}