#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 200050
using namespace std;
typedef long long LL;
int n,m;
bool divable[maxn];
void calc(int p,int k)
{
// cout<<"calc:"<<p<<" "<<k<<endl;
int cnt=0;
for (int i=1;i<n;++i)
{
int a=i,b=n-i+1;
int cnta,cntb;
for (cnta=0;a%p==0;a/=p)
// cout<<a<<endl,
++cnta;
for (cntb=0;b%p==0;b/=p)
// cout<<b<<endl,
++cntb;
cnt+=cntb-cnta;
// cout<<i<<" "<<cnt<<endl;
if (cnt<k)
divable[i]|=1;
}
}
int main()
{
freopen("irre.in","r",stdin);
freopen("irre.out","w",stdout);
cin>>n>>m;
--n;
divable[0]=divable[n]=1;
for (int i=2;m!=1&&i*i<=m;++i)
{
if (m%i==0)
{
int k=0;
for (;m%i==0;m/=i)
++k;
calc(i,k);
}
}
if (m!=1)
calc(m,1);
int ans=0;
// for (int i=0;i<=n;++i) cout<<divable[i]<<" "; cout<<endl;
for (int i=0;i<=n;++i)
if (divable[i]==0)
++ans;
printf("%d\n",ans);
for (int i=0;i<=n;++i)
if (divable[i]==0)
printf("%d\n",i+1);
return 0;
}