【题目分析】
唯一分解定理+组合数递推。
【代码】
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int top=0,n,m,cnt=0;
int a[100010],p[100010],now[100010],ans[100010];
int main()
{
scanf("%d%d",&n,&m);
for (int i=2;i*i<=m;++i)
{
if (m%i==0)
{
a[++top]=i;
while (m%i==0)
{
m/=i;
p[top]++;
}
}
}
if (m>1) a[++top]=m,p[top]=1;
// for (int i=1;i<=top;++i) printf("%d ",a[i]); printf("\n");
// for (int i=1;i<=top;++i) printf("%d ",p[i]); printf("\n");
for (int i=1;i<n-1;++i)
{
int x=n-i,y=i;
for (int j=1;j<=top;++j)
while (x%a[j]==0)
{
x/=a[j];
now[j]++;
}
for (int j=1;j<=top;++j)
while (y%a[j]==0)
{
y/=a[j];
now[j]--;
}
int flag=1;
for (int j=1;j<=top;++j)
if (now[j]<p[j]) {flag=0; break;}
if (flag) ans[++cnt]=i+1;
}
printf("%d\n",cnt);
for (int i=1;i<=cnt;++i)
printf("%d%c",ans[i],i==cnt?'\n':' ');
}