#include <stdio.h>
#include <string.h>

struct loong {
	int	l;
	char s[100000];
};

void mul(loong & a, long b) {
	long	i, sum;
	sum=0;
	for (i=0; i<a.l; i++) {
		sum=sum+b*a.s[i];
		a.s[i]=sum%10;
		sum/=10;
	}
	i=a.l;
	while (sum) {
		a.s[i++]=sum%10;
		sum/=10;
	}
	a.l=i;
}

void div(loong & a, long b, loong & c) {
	int		i;
	long	n=0;
	for (i=0; i<a.l; i++) c.s[i]=0;
	for (i=a.l-1; i>=0; i--) {
		n=n*10+a.s[i];
		c.s[i]=n/b;
		n=n%b;
	}
	i=a.l-1;
	while (i>=0 && c.s[i]==0) i--;
	c.l=i+1;

}

int rem(loong & a, long b) {
	int		i;
	long	n=0;
	for (i=a.l-1; i>=0; i--) {
		n=n*10+a.s[i];
		n=n%b;
	}
	return n;
}

void out(loong &a, FILE *F) {
	int		i;
	for (i=a.l-1; i>=0; i--) fprintf(F,"%c",a.s[i]+'0');
	fprintf(F,"\n");
}

void inp(loong &a, FILE *F) {
	int		i;
	char	s[1000];
	fscanf(F,"%s",s);
	a.l=strlen(s);
	for (i=0; i<a.l; i++) a.s[i]=s[a.l-1-i]-'0';
}



int main() {
	FILE	*FI, *FO;
	FI=fopen("irrelevant.in","rt");
	FO=fopen("irrelevant.out","wt");
	long	m, n, i, j;
	fscanf(FI,"%ld %ld",&n,&m);
	loong  a, b;
	a.l=1;
	a.s[0]=1;

	int		cnt=0;
	long	nums[60000];

	for (i=0; i<(n>>1)+1; i++) {
		if (rem(a,m)==0) {
			nums[cnt++]=i;
		}
		mul(a,n-i-1);
		div(a,i+1,b);
		//out(a,FO);
		a=b;
	}
	long cnt2=cnt*2;
	if (n&1) cnt2--;
	fprintf(FO,"%d\n",cnt2);
	for (i=0; i<cnt; i++) fprintf(FO,"%ld ",nums[i]+1);
	if (n&1) cnt--;
	for (i=cnt-1; i>0; i--) fprintf(FO,"%ld ",n-nums[i]);
	if (i>1) fprintf(FO,"%ld",n-nums[0]);
	fprintf(FO,"\n");
			
	fclose(FI);
	fclose(FO);
	return 0; 
}

