Hash function
Time limit3sMemory limit256 MB
Count the length-N lowercase words whose repeated multiply-by-33 xor hash modulo 2^M equals K.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Hash map, Brute force, Number theory
- Solved
- No attempts yet
Problem
Changyoung is writing a hash function for a systems programming assignment. The function turns a word into a number and is defined recursively.
Here is the empty word, is a word, and is the letter appended to it. A word consists of lowercase letters only. is bitwise XOR (), and gives the position of in the alphabet (, ). is the remainder of divided by .
With the hash values come out like this.
Write a program that counts the words of length whose hash value is .
Input
The first line contains , , and , separated by spaces. (, , )
Output
Print the number of words of length whose hash value is .
Hint
For , , the words that satisfy the condition are dxl, hph, lxd, xpx.