求2-100中的完数(因子之和等于它本身的数称为完数,如6=1+2+3)。

2025-03-06 14:51:42
推荐回答(1个)
回答1:

#include "stdafx.h"
#include "string"
#include "iostream"

using namespace std;

/*
求2-100中的完数(因子之和等于它本身的数称为完数,如6=1+2+3)。
*/

const int MAX=10000;//上限

int _tmain(int argc, _TCHAR* argv[])
{
for (int i=2;i {
int total=0;
for (int j=1;j {
if (i%j==0) total+=j;
}
if (total==i) cout< }
return 0;
}