您的位置:首页 > Web前端

HDU 1323 Perfection (水题)

2015-09-09 17:09 267 查看
题目大意:输入一系列数,以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
&& a
) 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: