爆搜233。
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define maxn 1000000 using namespace std; long long prime[maxn+50],cnt=0,s,stack[maxn],top=0,sqrts; bool vis[maxn+50]; void get_table() { for (long long i=2;i<=maxn;i++) { if (!vis[i]) prime[++cnt]=i; for (long long j=1;j<=cnt && i*prime[j]<=maxn;j++) { vis[i*prime[j]]=true; if (i%prime[j]==0) break; } } } bool judge(long long x) { if (x<=maxn) return !vis[x]; long long top=sqrt(x); for (long long i=1;prime[i]<=top;i++) { if (x%prime[i]==0) return false; } return true; } void dfs(long long x,long long s,long long ans) { if (s==1) {stack[++top]=ans;return;} if ((s-1>sqrts) && (judge(s-1))) stack[++top]=ans*(s-1); for (long long i=x;prime[i]<=sqrts;i++) { long long ret=1,kr=prime[i]; for (long long j=1;kr+ret<=s;j++) { if (s%(kr+ret)==0) dfs(i+1,s/(kr+ret),ans*kr); ret+=kr;kr*=prime[i]; } } } int main() { get_table(); while (scanf("%lld",&s)!=EOF) { sqrts=sqrt(s);top=0; dfs(1,s,1); sort(stack+1,stack+top+1); printf("%lld\n",top); for (long long i=1;i<=top-1;i++) printf("%lld ",stack[i]); if (top>=1) printf("%lld\n",stack[top]); } return 0; }