This page is still under construction.

Parts of this page are still being built. What you see may change.

Hash function

Time limit3sMemory limit256 MB

Summary
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.

  • f(ε)=0f(\varepsilon) = 0
  • f(w+x)=((f(w)×33)⊕ord(x)) mod 2Mf(w + x) = ((f(w) \times 33) \oplus \mathrm{ord}(x)) \bmod 2^M

Here ε\varepsilon is the empty word, ww is a word, and xx is the letter appended to it. A word consists of lowercase letters only. ⊕\oplus is bitwise XOR (0110⊕1010=11000110 \oplus 1010 = 1100), and ord(x)\mathrm{ord}(x) gives the position of xx in the alphabet (ord(a)=1\mathrm{ord}(a) = 1, ord(z)=26\mathrm{ord}(z) = 26). A mod BA \bmod B is the remainder of AA divided by BB.

With M=10M = 10 the hash values come out like this.

  • f(a)=1f(a) = 1
  • f(aa)=32f(aa) = 32
  • f(kit)=438f(kit) = 438

Write a program that counts the words of length NN whose hash value is KK.

Input

The first line contains NN, KK, and MM, separated by spaces. (1≤N≤101 \le N \le 10, 0≤K<2M0 \le K < 2^M, 6≤M≤256 \le M \le 25)

Output

Print the number of words of length NN whose hash value is KK.

Hint

For N=3N = 3, K=16K = 16, M=10M = 10 the words that satisfy the condition are dxl, hph, lxd, xpx.

Examples3

  1. Example 1

    Input
    1 0 10
    
    Expected output
    0
    
  2. Example 2

    Input
    1 2 10
    
    Expected output
    1
    
  3. Example 3

    Input
    3 16 10
    
    Expected output
    4