Irrelevant Elements

Time limit2sMemory limit128 MB

Summary
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 00 to m−1m-1.

He first fixes nn and generates nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, each in the range 00 to m−1m-1. He then repeatedly replaces the current array with the array of sums of adjacent elements: from a1,a2,…,ana_1, a_2, \ldots, a_n he forms a1+a2,a2+a3,…,an−1+ana_1 + a_2, a_2 + a_3, \ldots, a_{n-1} + a_n (which has n−1n-1 elements), and applies the same step again and again until a single number remains. That last number, taken modulo mm, 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 n=3n = 3 and m=2m = 2 the result never depends on a2a_2.

Call the ii-th original element irrelevant if the final result never depends on aia_i, no matter how the other numbers are chosen. Given nn and mm, determine which elements are irrelevant.

Input

A single line with two integers nn and mm (1≤n≤100 0001 \le n \le 100\,000, 2≤m≤1092 \le m \le 10^9).

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 ii of all irrelevant elements. If there are no irrelevant elements, print an empty second line.

Examples1

  1. Example 1

    Input
    3 2
    
    Expected output
    1
    2