#GL0000256. Cặp lũy thừa (Power Pair)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cặp lũy thừa (Power Pair)
Power Pair
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a prime number . Consider ordered pairs of integers such that both and are between and , inclusive.
A pair is valid if there exists at least one positive integer such that the remainder of upon division by is , equivalently
Even if several positive exponents satisfy the condition, count that ordered pair only once. The pairs and are distinct whenever .
Count the valid ordered pairs and output the count modulo .
Input
The only line contains the prime number .
Output
Print one integer: the number of valid ordered pairs , modulo .
Subtasks
- Subtask 1 (20 points): ; is prime.
- Subtask 2 (30 points): ; is prime.
- Subtask 3 (50 points): ; is prime.
Examples
Example 1
Input
3
Output
4
Explanation
For , the possible values of are , , and . For , all positive powers are , so only works. For , only works. For , the remainders of consecutive powers are , so either or works. The four valid pairs are , , , and .
Example 2
Input
11
Output
64
Explanation
For , consider . The numbers of reachable remainders from positive powers of each are , respectively. For example, the positive powers of yield the repeating sequence , giving five possible values of . Therefore the total count is .
Example 3
Input
998244353
Output
329133417
Explanation
Here is large, so enumerating ordered pairs is impractical. We have . Grouping nonzero values by the number of distinct remainders attainable by positive powers, and adding the pair , yields modulo .