Hash Hacking
Time limit1sMemory limit1024 MB
Count the length-N sequences over M symbols whose weighted sum mod M equals H, printed modulo 1000000007.
- Level
Easy3 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Yeondu, the operator of Green.com, has stopped storing passwords as plain text. From now on, passwords will be stored after applying a hash function. The only hash function Yeondu knows is the rolling hash function often used in competitive programming problems, so Yeondu decided to adapt it.
A Green.com password must have exactly characters, and each character must be one of allowed characters. If you map each allowed character to an integer starting from , a password can be written as an array of length where every element is between and inclusive.
After the password is written as , the following hash function is applied using a predetermined integer .
For example, take , , and . Then . Here is the remainder operation, and since , we have . The hash value is always an integer between and inclusive.
Jaehyun hacked the hash of an administrator account at Green.com and wants to work backward to find the original password. Green.com allows passwords in total. Jaehyun wants to know how many of them have the hash value he recovered. Compute this count for him.
Input
The first line contains three integers , , and ().
The second line contains the recovered hash value ().
Output
Print the number of passwords whose hash value is , modulo ().