Young cryptoanalyst Georgie is investigating different schemes of generating random integer numbers ranging from 0 to m−1. He thinks that standard random number generators are not good enough, so he has invented his own scheme that is intended to bring more randomness into the generated numbers. First, Georgie chooses n and generates n random integer numbers ranging from 0 to m−1. Let the numbers generated be a1,a2,...,an. After that Georgie calculates the sums of all pairs of adjacent numbers, and replaces the initial array with the array of sums, thus getting n−1 numbers: a1+a2,a2+ a3,...,an−1 + an. Then he applies the same procedure to the new array, getting n−2 numbers. The procedure is repeated until only one number is left. This number is then taken modulo m. That gives the result of the generating procedure. Georgie has proudly presented this scheme to his computer science teacher, but was pointed out that the scheme has many drawbacks. One important drawback is the fact that the result of the procedure sometimes does not even depend on some of the initially generated numbers. For example, if n = 3 and m = 2, then the result does not depend on a2. Now Georgie wants to investigate this phenomenon. He calls the i-th element of the initial array irrelevant if the result of the generating procedure does not depend on ai. He considers various n and m and wonders which elements are irrelevant for these parameters. Help him to find it out.
Input Input file contains several datasets. Each datasets has n and m (1 ≤ n ≤ 100000, 2 ≤ m ≤ 109) in a single line.
Output
On the first line of the output for each dataset print the number of irrelevant elements of the initial array for given n and m. On the second line print all such i that i-th element is irrelevant. Numbers on the second line must be printed in the ascending order and must be separated by spaces.
Sample Input
3 2
Sample Output
1 2
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100005;
int fac_c[100];
int fac[100][2];//第0列存放质因子,第一列其指数
int a[N];
void Factor(int m)//唯一分解式
{
int &num=fac[0][0];
num=0;
int i;
for(i=2; i*i<=m; i++)
{
if(m%i==0)
{
fac[++num][0]=i;
fac[num][1]=0;
while(m%i==0)
{
fac[num][1]++;
m/=i;
}
}
}
if(m>1)//如果m>1则为质数
{
fac[++num][0]=m;
fac[num][1]=1;
}
}
bool Check(int n,int j)
{
int num=fac[0][0];
int a=n-j;
int b=j;
int i;
for(i=1;i<=num;i++)
{
int p=fac[i][0];
int &q=fac_c[i];
for(;a%p==0;a/=p,q++);
for(;b%p==0;b/=p,q--);
}
for(i=1;i<=num;i++)//判断c(n,k)是否为m的倍数
{
if(fac[i][1]>fac_c[i])
return false;
}
return true;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int count=0;
Factor(m);
memset(fac_c,0,sizeof(fac_c));
int i;
for(i=1; i<=n-1; i++)
{
if(Check(n,i)) a[count++]=i+1;//a数组储存无关的数的下标
}
printf("%d\n",count);
for(i=0;i<=count-1;i++)
{
if(i==0) printf("%d",a[i]);
else printf(" %d",a[i]);
}
printf("\n");
}
return 0;
}