#include <fstream.h>

int main()
{
	ifstream cin("irrelevant.in");
	ofstream cout("irrelevant.out");
	int n, m;
	cin >> n >> m;
	int i = 2;
	bool p[50002] = {false};
	int num[50002];
	int count[50002];
	int bc = 0;
	while (m > 1)
	{
		if (m % i == 0)
		{
			num[bc] = i;
			count[bc] = 0;
			while (m % i == 0)
			{
				++count[bc];
				m /= i;
			}
			++bc;
		}
		++i;
	}
	int current[50002] = {0};
	int a = n - 1;
	int s = 0;
	for (i = 2; i <= (n + 1) / 2; ++i)
	{
		int j = 2;
		while (true)
		{
			int u;
			for (u = 0; u == bc || num[u] < j; ++u)
			{
				if (u == bc) break;
			}
			if (u == bc)
				break;
			if (num[u] == j)
				while (a % j == 0)
				{
					++current[u];
					a /= j;
				}
			++j;
		}
		int q = i - 1;
		j = 2;
		while (true)
		{
			int u;
			for (u = 0; u == bc || num[u] < j; ++u)
			{
				if (u == bc) break;
			}
			if (u == bc)
				break;
			if (num[u] == j)
				while (q % j == 0)
				{
					--current[u];
					q /= j;
				}
			++j;
		}
		p[i] = true;
		for (j = 0; j < bc; ++j)
			if (current[j] < count[j])
			{
				p[i] = false;
				break;
			}
		p[n - i + 1] = p[i];
		if (p[i])
		{
			++s;
			if (!(n % 2 == 1 && i == n/2 + 1))
				++s;
		}
	}
	cout << s << endl;
	for (i = 1; i < n; ++i)
		if (p[i])
			cout << i << ' ';
	cout << endl;
	return 0;
}