#include	<stdio.h>

int cprimes;
int primes[10000];

void PrebuildPrimes(void)
{
	cprimes = 0;
	for (int i = 2; i < 50000; ++i)
	{
		int j = 0;
		while ( (j < cprimes) && i % primes[j] )
			++j;
		if (j == cprimes)
		{
			primes[cprimes] = i;
			++cprimes;
		}
	}
}

int cmuls;
int muls[1000];
int pmuls[1000];

int main(void)
{
	freopen("irrelevant.in", "r", stdin);
	freopen("irrelevant.out", "w", stdout);

	PrebuildPrimes();

	int n, m;
	scanf("%d %d", &n, &m);

	cmuls = 0;
	int i;
	for (i = 0; i < cprimes; ++i)
	{
		if ( m % primes[i] == 0 )
		{
			int power = 0;
			while (m % primes[i] == 0)
			{
				m /= primes[i];
				++power;
			}
			muls[cmuls] = primes[i];
			pmuls[cmuls] = power;
			++cmuls;
		}
	}

	if (m != 1)
	{
		muls[cmuls] = m;
		pmuls[cmuls] = 1;
		++cmuls;	
	}

	int res[100000];
	for (i = 1; i < n - 1; ++i)
		res[i] = 1;

	for (i = 0; i < cmuls; ++i)
	{
		int d = 0;

		int j;
		for (j = 1; j < n - 1; ++j)
		{			
			int power = 0;
			int k = n - j;
			while (k % muls[i] == 0)
			{
				k /= muls[i];
				++power;
			}

			d += power;

			power = 0;
			k = j;
			while (k % muls[i] == 0)
			{
				k /= muls[i];
				++power;
			}
			d -= power;
		
			if (d < pmuls[i])
				res[j] = 0;
		}
	}

	int count = 0;
	for (i = 1; i < n - 1; ++i)
		if (res[i])
			++count;

	printf("%d\n", count);
	for (i = 1; i < n - 1; ++i)
		if (res[i])
			printf("%d ", i + 1);

	return 0;
}