#include<fstream.h>
#include<math.h>

const int max = 100009;
int baz[max],cur[max],can[max],luts[max];

int main()
{
	ifstream cin("irrelevant.in");
	ofstream cout("irrelevant.out");
	int n,m;
	cin >> n >> m;
	n--;
	int j = 0, i = 2;
	bool nor = true;
	while (m > 1) 
	{
		if (m % i == 0)
		{	
			m /= i;  
			if (nor)
			{	
				baz[j] = i;
				can[j] = 1;
			}
			else 
			{
				can[j]++;
				nor = false;
			}
		}
		else 
		{
			i++;
			if (!nor)
			{
				nor = false;
				j++;
			}
		}
	}
	for (i = 0; i <= j; i++)
	{
		int t = n;
		while(t % baz[i] == 0)
		{
			t /= baz[i];
			cur[i] ++;
		}
	}
	i = 1;
	int kan = 0;
	while (i <= n-1)
	{
		bool res = true;
		for (int p = 0; p <= j; p++)
		{
			res = res & (cur[p] >= can[p]);
			int t = n-i;
			while (t % baz[p] == 0)
			{
				cur[p]++;
				t /= baz[p]; 
			}
			t = i+1;
			while (t % baz[p] == 0)
			{
				cur[p]--;
				t /= baz[p];
			}
		}
		if (res)
			luts[kan++] = i+1;
		i++;
	}
	cout << kan << endl;
	for (i = 0; i < kan; i++)
		cout << luts[i] << " ";
	cout << endl;
	return 0;
}