#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int s;
int tot;
int a[10000001];
int ysh(int x){
int ans=1+x;
for(int i=2;i<x;i++){
if(x%i==0)ans+=i;
}
return ans;
}
int main(){
while(cin>>s){
tot=0;
memset(a,0,sizeof a);
for(int i=2;i<s;i++){
if(s==ysh(i))a[tot++]=i;
}
cout<<tot<<endl;
for(int i=0;i<tot;i++)printf("%d ",a[i]);
cout<<endl;
}
}
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 50000;
int primes[N], cnt;
bool st[N];
int ans[N], len;
void get_primes(int n)
{
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] * i <= n; j ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
bool is_prime(int x)
{
if (x < N) return !st[x];
for (int i = 0; primes[i] <= x / primes[i]; i ++ )
if (x % primes[i] == 0)
return false;
return true;
}
void dfs(int last, int prod, int s)
{
if (s == 1)
{
ans[len ++ ] = prod;
return;
}
if (s - 1 > (last < 0 ? 1 : primes[last]) && is_prime(s - 1))
ans[len ++ ] = prod * (s - 1);
for (int i = last + 1; primes[i] <= s / primes[i]; i ++ )
{
int p = primes[i];
for (int j = 1 + p, t = p; j <= s; t *= p, j += t)
if (s % j == 0)
dfs(i, prod * t, s / j);
}
}
int main()
{
get_primes(N - 1);
int s;
while (cin >> s)
{
len = 0;
dfs(-1, 1, s);
cout << len << endl;
if (len)
{
sort(ans, ans + len);
for (int i = 0; i < len; i ++ ) cout << ans[i] << ' ';
cout << endl;
}
}
return 0;
}
作者:yxc
链接:https://www.acwing.com/activity/content/code/content/197156/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。