atcoder#ARC126F. [ARC126F] Affine Sort
[ARC126F] Affine Sort
Score : points
Problem Statement
Given is a sequence of positive integers .
For a positive integer , let be the number of triples of integers that satisfy all of the following conditions.
- .
- and .
- For each , let be the remainder when is divided by . Then, holds.
It can be proved that the limit exists. Find this value modulo (see Notes).
Notes
We can prove that the limit in question is always a rational number. Additionally, under the Constraints of this problem, when that number is represented as using two coprime integers and , we can prove that there is a unique integer such that and . Find this .
Constraints
- are positive integers such that .
- if .
Input
Input is given from Standard Input in the following format:
Output
Print modulo .
3
3 1 2
291154603
- For example, when , we have , , , which satisfy .
- We have , , , , .
- We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = \frac{1}{24}$.
3
5 9 2
832860616
We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = \frac{55}{1008}$ .
2
2 3
166374059
We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = \frac{1}{6}$.
4
4 5 3 2
0
We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = 0$.