数论+爆搜
详见这位大佬https://blog.csdn.net/eolv99/article/details/39644419
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100000;
int s,p[N+5],tot,ans[N+5],con;
bool v[N+5];
bool ok(int x)
{
if(x==1)
return 0;
if(x<=N)
return !v[x];
for(int i=1;p[i]*p[i]<=x;i++)
if(x%p[i]==0)
return 0;
return 1;
}
void dfs(int la,int nw,int w)
{
if(w==1)
{
ans[++con]=nw;
return;
}
if(w-1>p[la]&&ok(w-1))
ans[++con]=nw*(w-1);
for(int i=la+1;p[i]*p[i]<=w;i++)
for(int j=p[i]+1,t=p[i];j<=w;t*=p[i],j+=t)
if(w%j==0)
dfs(i,nw*t,w/j);
}
int main()
{
for(int i=2;i<=N;i++)
{
if(!v[i])
p[++tot]=i;
for(int j=1;i*p[j]<=N;j++)
{
v[i*p[j]]=1;
if(i%p[j]==0)
break;
}
}
while(scanf("%d",&s)!=EOF)
{
con=0;
dfs(0,1,s);
sort(ans+1,ans+con+1);
printf("%d
",con);
for(int i=1;i<=con;i++)
printf("%d%c",ans[i],i==con?'
':' ');
}
return 0;
}