# include <iostream.h>
# include <fstream.h>
ifstream input("irrelevant.in");
ofstream output ("irrelevant.out");
int *a;
int *b;


int main()
{
	int n,m;
	int x,y,i,j,l,k;

	int count=0 ;
	int index=-1;
	int N;


	input>>N>>m;

	n=N-1;
b=new int[n];
	for (k=1;k<=n;k++)
	{
		x=0;

		cout<<"k="<<k<<endl;

		a=new int[k+1];
		
		for (i=0;i<k;i++)
		{
			a[i]=n-i;
		
		}

		
		
		
		for (i=k;i>1;i--)
		{
			for (j=0;j<k+1;j++)
			{
				if (a[j]%i==0)
				{
					a[j]/=i;
					break;
			
				}
			}
			if (j==k && a[j]%k!=0 )
				cout<<"ERRRRRE"<<endl;
		}

		cout<<endl;

		cout<<"a"<<endl;


		for (i=0;i<k;i++)
			cout<<a[i]<<" ";
		cout<<endl;
	


		x=a[0]%m;
		for (i=1;i<k;i++)
		{
			x=(x*(a[i]%m))%m;
		}

		cout<<"x="<<x<<endl;




		if (x==0)
		{
			index++;
			count++;
			b[index]=k;
			cout<<"::"<<k<<endl;
		}
			cout<<"B="<<endl;

	}
	output<<count;
	output<<endl;
	
	cout<<endl;
		for (i=0;i<=index;i++)
			cout<<b[i]<<" ";


	for (i=0;i<=index;i++)
		output<<b[i]+1<<" ";



	return 0;
}




	


















