NUMG - God of Number Theory
In ACM_DIY, there is one master called “ShaZai”. As we know, he is the god of “Number Theory”. He always kills the problem about “Number Theory” in seconds! But of course we do not have any idea about these problems. One day in ACM_DIY, ShaZai asks us one problem:
You are given three non-negative integers A, B and K, you are expected to find the number of numbers that satisfy:
- X^A = B (mod (2K + 1))
- X is in the range [0, 2K];
Of course we have no idea about this problem, so could you help us?
Input
The first line is one integer T indicates the number of the test cases. (T <= 1000)
Then for every case, only one line contains three integers A, B and K. (1 <= A, B <= 10^9, 1 <= K <= 5 * 10^8)
Output
Output the answer in a single line.
Example
Input: 3 213 46290770 80175784 3 46290770 80175784 3333 46290770 80175784 Output: 27 27 297
hide comments
aekdycoin:
2011-05-19 14:57:46
no always exist |
|
Piotr KÄ…kol:
2011-04-03 14:37:36
@Tony Beta Lambda - "you are expected to find the number of number that satisfy". No if there's no such X You should print 0. |
|
Tony Beta Lambda:
2011-04-03 12:50:14
Does a solution always exist? What is the answer for 2 3 4? |
|
[Rampage] Blue.Mary:
2010-12-16 12:12:26
"X^A = B( mod (2K + 1) )" actually means "X^A mod (2K + 1) = B mod (2K + 1)". |
Added by: | aekdycoin |
Date: | 2010-12-15 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |