#include <stdio.h>

FILE *f;
long n, m;
long mnozh[100];
int step[100];
long mk;
int ir[100000], irk; //irrele i ih kolvo

int del(long p, long mn)
{ //vozvraqaet stepen' delenija
	long s=0;
	//if(mn==0) while(1);
	while(p>=mn)
	{
		p/=mn;
		s+=p;
	}
	return s;
}

int main()
{
	int s, j;
	f = fopen("irrelevant.in","rt");
	fscanf(f, "%ld %ld", &n, &m);
	fclose(f);

	//Razlagem m na mnozh
	long i; mk=0;
	for(i=0; i<100; i++) step[i]=0;
	for(i=2; i*i<=m;i++)
	{
		s=0;
		while(!(m%i)) {m/=i; s++;} 
		mnozh[mk]=i; step[mk++]=s;
	}
	if(m!=1) {mnozh[mk]=m; step[mk++]=1;}

	f = fopen("irrelevant.out","wt");
	//Proverka
	irk=0;
	for(i=0; i<n; i++)
	{
		s=1;
		for(j=0; j<mk; j++)
		{
//			fprintf(f, "%ld %ld %ld %d\n",del(n-1,mnozh[j]),del(n-1-i,mnozh[j]),del(i, mnozh[j]),step[j]);
			if(del(n-1,mnozh[j])<del(n-1-i,mnozh[j])+del(i, mnozh[j])+step[j])
			{s=0; break;}
		}
		if(s) ir[irk++]=i;
	}

	fprintf(f,"%d\n", irk);
//	for(i=0; i<mk; i++) fprintf(f, "%ld-%d ", mnozh[i],step[i]);
//	fprintf(f,"\n");
	for(i=0; i<irk; i++) fprintf(f, "%d\n", ir[i]+1);
	fclose(f);

	return 0;
}