#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=2;i<=n;i++)
{
int sum=0;
for(int j=1;j<=i/2;j++)
{
if(i%j==0)
sum+=j;
}
if(sum==i)
{
cout<<i<<" its factors are ";
for(int j=1;j<=i/2;j++)
{
if(i%j==0)
cout<<j<<' ';
}
cout<<endl;
}
}
return 0;
#include<iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=2;i<=n;i++)
{
int sum=0;
for(int j=1;j<=i/2;j++)
{
if(i%j==0)
sum+=j;
}
if(sum==i)
{
cout<<i<<" its factors are ";
for(int j=1;j<=i/2;j++)
{
if(i%j==0)
cout<<j<<' ';
}
cout<<endl;
}
}
return 0;
}
好像让我给写麻烦了......