KBASEEN - Acceptable numbers
Sitting in front of computer has made Byteasar's eye sight very bad. He has to wear glasses to fix it. But Byteasar doesn't like it. So everything associated with glasses is disliked by him.
Byteasar has been working with different numeral systems. When listing numbers, he knows exactly which of them aren't liked by him. Of course these numbers have two zeros next to each other. Now he is wondering: how many n-digits numbers in k-base numeral system he is able to accept. There could be many of them so print the result modulo m.
Input
First there is a t (0 < t < 1001), number of test cases.
Each test contains three number: n (0 < n < 1018), k (1 < k < 1018) and m (1 < m < 1018). n is a length of the number, k - digits quantity in given numeral system.
Output
For each test print answer divided modulo m.
Example
Input: 2
4 2 100
3 10 10000
Output: 5
891
hide comments
Ketan Chandak:
2016-07-10 13:10:29
Given the constraints, even long long will give WA. Why keep constraints like that?
|
|
Alex Anderson:
2015-10-10 08:06:40
Would have been a little trickier if it he accepted only those with "00". |
|
Grzegorz Spryszyñski:
2015-10-02 11:30:03
Thanks. You are not the first one who made this mistake.
|
|
gokulnc:
2015-09-30 17:04:02
Okay, for test case 1 (4 2 100)
|
Added by: | Grzegorz Spryszyński |
Date: | 2015-09-19 |
Time limit: | 1s-2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |