Irrelevant Elements
Time limit2sMemory limit128 MB
Repeatedly replace an array with adjacent sums until one value remains mod m; find which original positions never affect that value.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Georgie is experimenting with a scheme for generating a pseudo-random integer in the range to .
He first fixes and generates integers , each in the range to . He then repeatedly replaces the current array with the array of sums of adjacent elements: from he forms (which has elements), and applies the same step again and again until a single number remains. That last number, taken modulo , is the output of the scheme.
A weakness of this scheme is that the final result sometimes does not depend on some of the originally generated numbers. For example, when and the result never depends on .
Call the -th original element irrelevant if the final result never depends on , no matter how the other numbers are chosen. Given and , determine which elements are irrelevant.
Input
A single line with two integers and (, ).
Output
On the first line, print the number of irrelevant elements. On the second line, print in ascending order, separated by single spaces, the indices of all irrelevant elements. If there are no irrelevant elements, print an empty second line.