#nt202. 逆元1
逆元1
Inverses 1
Problem Description
Given a prime , find the inverses of modulo .
Since the output could be very large, you only need to output the XOR sum of these inverses.
Input Format
One line with two integers .
Output Format
One integer: the XOR sum of the inverses of to modulo .
Sample Input
10007 1000
Sample Output
14675
Constraints
For all data, it is guaranteed that , , and is prime.
Hint
- You can compute all inverses in linear time using the recurrence $inv[i] = p - \lfloor p/i\rfloor \cdot inv[p \bmod i] \bmod p$ (valid for a prime ), or use the fact that with fast exponentiation (slower). XOR the results together at the end.