#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
//1050 完数
int isWS(int n){
int sum=0;
//if(n==1) return -1;
for(int i=1;i<n;i++)
if(n%i==0) sum+=i;
//printf("sum=%d\n",sum);
if(sum==n) return n;
else return -1;
}
vector<int> N;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
//printf("ans=%d",isWS(n));
N.clear();
for(int i=1;i<=n;i++){
if(isWS(i)>0)
N.push_back(i);
}
for(int i=0;i<N.size();i++){
if(i==N.size()-1)
printf("%d\n",N[i]);
else
printf("%d ",N[i]);
}
}
return 0;
}
/**************************************************************
Problem: 1050
User: cust123
Language: C++
Result: Accepted
Time:230 ms
Memory:1520 kb
****************************************************************/
题目1050:完数
最新推荐文章于 2023-12-03 15:09:22 发布