Topic links : http://codeup.cn/problem.php?cid=100000592&pid=0
Description Title
find the number in the finished 1-n, the number of the called number is finished, all factors which sum is equal to its own, there are three factors such as 1,2,3,1 6 + 2 + 3 = 6, then the number 6 is finished. End i.e. the number and the sum is equal to the number of all factors.
Input
test data set multiple, input n, not n data range.
Output
for each set of input, output finished counting all the 1-n. If there are cases of multiple digital output, separated by a space, the final output with no extra spaces.
Sample input
6
Sample output
6
Code
#include<stdio.h>
bool comput(int n) {
int sum = 0;
for(int i = 2; i <= n / 2; i++) {
if(n % i == 0)
sum += i;
}
if(sum == n - 1)
return true;
else
return false;
}
int main() {
int n;
while(scanf("%d", &n) != EOF) {
int t = 0;
for(int i = 2; i <= n; i++) {
if(comput(i) == true){
if(t > 0)
printf(" ");
printf("%d", i);
t++;
}
}
printf("\n");
}
return 0;
}