Restricted Arrays
Time limit4sMemory limit256 MB
Count the moduli M up to n for which some integer array satisfies a[x]+1 = a[y] (mod M) for every given pair, and list them.
- Level
Hard8 of 10
- Topics
- Graph, Union-find, Number theory, Math
- Solved
- No attempts yet
Problem
Let be a positive integer. Find the number of integers with for which there exists an array of integers satisfying the following conditions:
Input
The first line contains two integers, and : the array size and the number of conditions ().
Each of the next lines contains two integers, and : the indices describing the corresponding condition ().
Output
On the first line, print an integer : the number of possible values of . On the second line, print the possible values of in increasing order.