HDU 1323 Perfection (水题)

来源:互联网 发布:淘宝宝贝评价没有了 编辑:程序博客网 时间:2024/05/01 08:22

题目大意:输入一系列数,以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;}
0 0
原创粉丝点击