If a number is exactly equal to the sum of all factors except itself, then this number is called a complete number

eg: The factor of 6 is 1, 2, 3, and 6=1+2+3, so 6 is the complete number, try to find all the complete numbers within 1000 and output

#include<stdio.h>
int main()
{
    
    
	int i,j,sum;
	for(i=1;i<=1000;i++){
    
    
		sum=0;
		for(j=1;j<i;j++){
    
    
			if(i%j==0){
    
    
				sum+=j;
			}
		}
		if(sum==i){
    
    
			printf("完数=%d\n",i); 
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/buxiangquaa/article/details/114989985