#include <fstream>

using namespace std;

ifstream fin("irrelevant.in");
ofstream fout("irrelevant.out");

inline int gcd(int a, int b)
{
	if (a == b)
		return a;
	int t;
	while (b) {
		t = a;
		a = b;
		b = a % b;
	}
	return a;
}

inline int np(int n, int p)
{
	int sum = 0;
	while ((n / p) != 0) {
		sum += n / p;
		p *= p;
	}
	return sum;
}

int main()
{
	int i;
	bool erat[32000];
	int n, m, s = 0, mparz[32000], mpast[32000], msize;
	bool a[100010];
	fin >> n >> m;

	for (i = 0; i < 32000; i++)
		erat[i] = true;
	erat[0] = false;
	erat[1] = false;
	for (i = 2; i < 32000; i++)
		if (erat[i]) {
			for (int j = 2 * i; j < 32000; j += i)
				erat[j] = false;
		}

	for (i = 0; i < 32000; i++)
		mpast[i] = 0;
	int k = 0;
	for (i = 2; i < 32000; i++)
		if (m % i == 0) {
			mparz[k] = i;
			while (m % i == 0) {
				m /= i;
				mpast[k]++;
			}
			k++;
		}
	if (m != 1) {
		mparz[k] = m;
		mpast[k++] = 1;
	}
	msize = k;

	for (i = 0; i < n; i++)
		a[i] = false;
	bool b;
	n--;
	for (int gorc = 1; gorc <= n; gorc++) {
		b = false;
		for (int k = 0; k < msize; k++) {
			int nas = np(n, mparz[k]);
			int kas = np(gorc, mparz[k]);
			int nmkas = np(n - gorc, mparz[k]);
			if (nas - kas - nmkas - mpast[k] < 0) {
				b = true;
				break;
			}
		}
		if (b)
			continue;
		else
			a[gorc] = true;
		s++;
	}

	fout << s << endl;
	for (i = 0; i < n; i++)
		if (a[i])
			fout << i + 1 << ' ';

	return 0;
}