[CCC 1996 01] Deficient, Perfect, and abundant

Source: Internet
Author: User

CCC Canadian High School of Information science Orsay

Remaining sources

CODEVS[3312]--CCC 1996 deficient, Perfect, and abundant--http://codevs.cn/problem/3312/

poj[1928]--perfection--http://poj.org/problem?id=1528

Codevs Description--Chinese titleTitle Description Description

Reads a positive integer n, which determines whether the integer is complete, or the number of losses or the surplus.

• If its approximate sum equals its own, then it is an end number (Perfect) (an approximate amount contains 1, but does not contain it itself).

• If its approximate and smaller than its own, then it is a loss (deficient) (the approximate number contains 1, but does not contain itself).

• If its approximate and greater than itself, then it is an IB (abundant) (an approximate number contains 1, but does not contain it itself).

Enter a description Input Description

Input file a total of two lines,

The first behavior is a positive integer n,

The second behaves n positive integers, separated by a space between them.

Output description Output Description

The output is n rows, which are 1th, respectively. The category of n number.

End: Perfect

Deficit Number: Deficient

Surplus Number: Abundant

Sample input Sample Input

3
4 6 12

Sample output Sample Output

4 is a deficient number.
6 is a perfect number.
are an abundant number.

Data range and Tips Data Size & Hint

1<=n<=2^31-1

POJ Description (English)Descriptionfrom The article number theory in the 1994 Microsoft Encarta: "If A, B, c is integers such. 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, and B is called a proper divisor of a. Even integers, which include 0, is multiples of 2, for example,-4, 0, 2, 10; An odd integer is a integer is not even, for example,-5, 1, 3, 9. A perfect number is a positive an integer that's equal to the sum of the-its positive, proper divisors; For example, 6, which equals 1 + 2 + 3, and, which equals 1 + 2 + 4 + 7 + +, is perfect numbers. A positive number that is not perfect are imperfect and is deficient or abundant according to whether the sum of its positi ve, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; Proper divisors 1, 2, 3, 4, 6, is abundant. "
Given a number, determine if it is perfect, abundant, or deficient. Inputa list of n positive integers (none greater than 60,000), with 1 <= N < 100. A 0 'll mark the end of the list. Outputthe first line of output should read perfection output. The next N lines of output should list for each input integer whether it was perfect, deficient, or abundant, as shown in t He example below. Format counts:the echoed integers should be right justified within the first 5 spaces of the output line, followed by 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  deficient  PERFECT    6  PERFECT  ABUNDANT60000  Abundant  deficient  496 perfectend of  OUTPUT
Sourcemid-atlantic 1996 Ideas

Using the number theory knowledge to calculate the approximate and the numbers quickly, see the program function.

Sample Example

Codevs:

varT,x:longint;functionans (n:longint): Longint;varI:longint;beginans:=0;  fori:=1  toN Do        begin            if(i*i=n) Then                beginans:=ans+i;                Break End; if(i*i>n) ThenBreak ; if(nMoDI=0) ThenAns:=ans+i+nDivi; End;End;proceduremain;varAnss,n:longint;beginread (n); ANSS:=ans (N)-N; ifAnss<n ThenWriteln (N,'is a deficient number.'); ifAnss=n ThenWriteln (N,'Is a perfect number.'); ifAnss>n ThenWriteln (N,'is an abundant number.');End;beginreadln (t);  forx:=1  toT Domain;End.
View Code

 POJ:

varT,x,n:longint;functionans (n:longint): Longint;varI:longint;beginans:=0;  fori:=1  toN Do        begin            if(i*i=n) Then                beginans:=ans+i;                Break End; if(i*i>n) ThenBreak ; if(nMoDI=0) ThenAns:=ans+i+nDivi; End;End;proceduremain;varanss,x,i:longint;s:ansistring;beginAnss:=ans (N)-N;    STR (n,s); X:=length (s);  fori:=1  to 5-X DoWrite' '); ifAnss<n ThenWriteln (N,'deficient'); ifAnss=n ThenWriteln (N,'PERFECT'); ifAnss>n ThenWriteln (N,'Abundant');End;beginWriteln ('Perfection OUTPUT');  whileTrue Do        beginread (n); ifn=0  Then                beginWriteln ('END of OUTPUT');                Halt End;        Main End;End.
View Code

[CCC 1996 01] Deficient, Perfect, and abundant

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.