#nt202. 逆元1

逆元1

Inverses 1

Problem Description

Given a prime pp, find the inverses of 1∼n1\sim n modulo pp.

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 p,np, n.

Output Format

One integer: the XOR sum of the inverses of 11 to nn modulo pp.

Sample Input

10007 1000

Sample Output

14675

Constraints

For all data, it is guaranteed that 2≤p≤109+72\leq p\leq 10^9+7, 1≤n≤min⁡(107,p−1)1\leq n\leq \min(10^7, p-1), and pp 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 pp), or use the fact that inv[i]≡ip−2(modp)inv[i] \equiv i^{p-2} \pmod p with fast exponentiation (slower). XOR the results together at the end.