I've seen others use a hard-coded list of the first 26 primes, but I find that ugly. My solution instead uses the Euler primes 41, 43, 47, 53, 61, etc computed by **n ^{2}+n+41** for n in 0..25. And the Mersenne prime 2

^{31}-1, aka

`INT_MAX`

. For example, the key for the string "abcz" is 41*43*47*691 modulo that Mersenne prime. Of course it's not collision-free, but seems pretty good and gets accepted here.I challenge you to find two non-anagram strings that have the same key :-). And if you succeed, I'll replace INT_MAX with a 50-bits prime and challenge you again :-D. I'd like to use a larger Mersenne prime, but unfortunately the next larger one is already bad, because it's 2^{61}-1 and my Euler prime for `'z'`

has 10 bits, so I'd get overflows in the multiplication.

```
bool isAnagram(string s, string t) {
return key(s) == key(t);
}
long key(string s) {
long result = 1;
for (char c : s) {
int n = c - 'a';
result = result * (n*n + n + 41) % INT_MAX;
}
return result;
}
```