Dhaka Regional ACM ICPC 2016 Preleminary Contest Solution I - Gadgets of Tomishu
I. Gadgets of Tomishu
Score: 1
CPU: 1s
Memory: 1200MB
CPU: 1s
Memory: 1200MB
Little Tomishu likes numbers. But he likes electronic gadgets (mobile, tablet, phablet, laptop and so on) more than numbers. His parents are trying to keep him engaged with numbers. So, they asked him to write down all the numbers of n length, consisting of only 0 and 1, and without any neighboring 1s. For example, if n = 3, he is supposed to write: 000, 001, 010, 100 and 101. Of course, Tomishu will write the numbers in increasing order. For each of the numbers, his parent will reward him with one of the k types of gadgets. Find out the number of ways he can get the gadgets. Two ways will be different if he received different gadget for the ith number for some i. For example, for n = 3, if there are k = 2 types of gadgets (say mobile and laptop), he can get the gadgets in 2 * 2 * 2 * 2 * 2 = 25 = 32 ways.
Since the answer can be quite big for the given n and k, you will also be given M. You need to provide the answer modulo M.
However, you should know that recently Tomishu’s interest shifted from electronic gadget to bookfacing.
Input
First line of the input is T (≤ 20), the number of test cases. Hence T lines will follow. Each of these lines will contain 3 positive integersn, k and M (1 ≤ n, k ≤ 100,000 and 1 ≤ M ≤ 1,000,000,000).
Output
For each of the cases print case number, followed by the answer. For details, please check the sample output.
Sample
Input | Output |
---|---|
2 3 2 100 4 3 1000 | Case 1: 32 Case 2: 561 |
Comments
Post a Comment