• [ACM


    Perfection

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 11   Accepted Submission(s) : 6

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    Problem Description

    From the article Number Theory in the 1994 Microsoft Encarta: "If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not 1/-1, b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant." 
    Given a number, determine if it is perfect, abundant, or deficient. 

    Input

    A list of N positive integers (none greater than 60,000), with 1 < N < 100. A 0 will mark the end of the list.

    Output

    The first line of output should read PERFECTION OUTPUT. The next N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below. Format counts: the echoed integers should be right justified within the first 5 spaces of the output line, followed by two blank spaces, followed by the description of the integer. The final line of output should read END OF OUTPUT.

    Sample Input

    15 28 6 56 60000 22 496 0
    

    Sample Output

    PERFECTION OUTPUT
       15  DEFICIENT
       28  PERFECT
        6  PERFECT
       56  ABUNDANT
    60000  ABUNDANT
       22  DEFICIENT
      496  PERFECT
    END OF OUTPUT
    

    Source

    Mid-Atlantic USA 1996


    解题思路:

    给定一个正整数,判断这个正整数所有正因子的和与该数的大小关系,正因子不能是该数本身,比如 6的正因子为1,2,3  ;  12 的正因子为 1,2,3,4,6 ,如果正因子之和等于该数则称为 perfect,如果大于该数 则称为 abundant ,如果小于该数则称为 deficient。思路是 用两个数组,一个存储输入的整数,一个存储对应整数所有正因子的和,然后对应比较就可以了。

    #include <iostream>
    #include <string.h>
    #include <algorithm>
    #include <stdio.h>
    #include <iomanip>
    #include <cmath>
    #include <stdlib.h>
    using namespace std;
    #define maxn 60000
    int num[102];//用来保存输入的整数
    int sum[102];//对应整数的正因子之和 如整数num[2]的所有正因子之和为sum[2]
    
    int main()
    {
        int shu;
        int ci=1;
        memset(num,0,sizeof(num));
        memset(sum,0,sizeof(sum));
        while(cin>>shu&&shu)
        {
            num[ci++]=shu;
        }  
    
        int i,j;
        for(i=1;i<=ci-1;i++)
        {
            for(j=1;j<num[i];j++)
                if(num[i]%j==0)
              sum[i]+=j;
    
        }//计算每个数的正因子之和
        cout<<"PERFECTION OUTPUT"<<endl;
        for(i=1;i<=ci-1;i++)
        {
            if(num[i]==sum[i])
                cout<<setw(5)<<num[i]<<"  "<<"PERFECT"<<endl;
            else if(num[i]<sum[i])
                cout<<setw(5)<<num[i]<<"  "<<"ABUNDANT"<<endl;
            else
                cout<<setw(5)<<num[i]<<"  "<<"DEFICIENT"<<endl;
        }
        cout<<"END OF OUTPUT"<<endl;//少了endl 不能Ac
    
        return 0;
    }
    

    运行截图:


  • 相关阅读:
    Vim的分屏功能
    vim简明教程
    trk压力测试工具(测试tcp)
    浅谈ThreadPool 线程池
    压力测试的概念
    wrk 网站压力测试
    windows下vim中文乱码处理
    java 新创建的类要重写的方法
    多线程代码示例
    System.out.print实现原理猜解
  • 原文地址:https://www.cnblogs.com/sr1993/p/3697821.html
Copyright © 2020-2023  润新知