题目大意:输入一系列数,以0结尾。最多100个 且每个数最大不超过60000. 然后求出每个数的所有真因子(即不包括本身的因子)之和。
由于 , 数据比较小, 可以直接暴力来解,另外注意输出格式即可。
代码
#include <iostream>
#include <iomanip>
using namespace std;
const int maxn = 110;
int main()
{
int a[maxn] , b[maxn] , n = 0;
while(cin >> a[n] && a[n]) n++;
for(int i = 0; i < n; i++)
{
int tmp = 0;
for(int j = a[i] / 2; j >= 1; j--) if(a[i] % j == 0) tmp += j;
b[i] = tmp;
}
cout << "PERFECTION OUTPUT" << endl;
for(int i = 0; i < n; i++)
{
cout << setw(5) << a[i] << " ";
if(b[i] == a[i]) cout << "PERFECT" << endl;
else if(b[i] > a[i]) cout << "ABUNDANT" << endl;
else cout << "DEFICIENT" << endl;
}
cout << "END OF OUTPUT" << endl;
return 0;
}