頁面視覺化搭建工具前生今世
阿新 • • 發佈:2020-10-20
#include <bits/stdc++.h> using namespace std; const int mn=5e4+77,mm=1e6+7; ll v[mn],p[mn],tot=0,tt=0; struct ccf { ll v; }ans[mm]; bool pd(ll x) { if(x==1) return false; if(x==2) return true; for(ll i=2;i<=sqrt(x);++i) if(x%i==0) return false; return true; } void dfs(ll k,ll re,ll x) { //cout<<k<<" "<<p[k]<<" "<<re<<" "<<x<<endl; if(x==1) { ans[++tt].v=re; return ; } if(x>p[k]&&pd(x-1)) { ++tt; ans[tt].v=(x-1)*re; //return ; } //if(k>tot||p[k]>=x) return ; for(ll j=k;j<=tot&&p[j]*p[j]<x;++j) { ll t=1,z=1; for(ll i=1;z<=x;++i) { t*=p[j]; z+=t; if(x%z==0) dfs(j+1,re*t,x/z); } } } bool cmp(ccf x,ccf y) { return x.v<y.v; } int main() { for(ll i=2;i<=mn-77;++i) { if(v[i]==0) { v[i]=i; p[++tot]=i; } for(ll j=1;j<=tot;++j) { if(p[j]>v[i]||p[j]*i>mn-77) break; v[i*p[j]]=p[j]; } } ll n; while(scanf("%lld",&n)!=EOF) { memset(ans,0,sizeof(ans)); tt=0; dfs(1,1,n); printf("%lld\n",tt); if(tt==0) continue; sort(ans+1,ans+1+tt,cmp); for(ll i=1;i<=tt;++i) printf("%lld ",ans[i]); printf("\n"); } return 0; }