-----------------------------------
Tony
Fri Jan 03, 2003 7:05 pm
CCC 1996 Stage1: Problem A: Deficient, Perfect, and Abundan
-----------------------------------
Write a program that repeatedly reads a positive integer, determines if the integer is deficient, perfect, or abundant, and outputs the number along with its classification.
A positive integer, n, is said to be perfect if the sum of its proper divisors equals the number itself. (Proper divisors include 1 but not the number itself.) If this sum is less that n, the number is deficient, and if the sum is greater than n, the number is abundant.
The input starts with the number of integers that follow. For each of the following integers, your program should output the classification, as given below. You may assume that the input integers are greater than 1 and less than 32500.
Sample input
3
4
6
12
--------------------------------------------------------------------------------
Sample output
4 is a deficient number.
6 is a perfect number.
12 is an abundant number.
Tony's Comment
Proper divisor is a number by which a number can be divided (excluding itself but including 1)
so for 4
1+2 = 3 --- 312 so 12 is abundant
-----------------------------------
Tony
Fri Jan 03, 2003 7:08 pm
official solution
-----------------------------------
here's the official solution
C Source Code
# include
FILE * infp;
FILE * outfp;
int t, /* number of test cases */
i, /* a counter */
n, /* a number to be classified */
sum; /* sum of divisors of n */
main()
{
infp = fopen( "dpa.in", "r");
outfp = fopen( "dpa.out", "w");
fscanf(infp, "%d\n", &t);
while (t>0) {
fscanf(infp, "%d\n", &n);
sum=0;
for (i=1; i n */ fprintf(outfp,"%d is an abundant number.\n",n);
t--; fprintf(outfp,"\n");
}
}
-----------------------------------
Tony
Fri Jan 03, 2003 7:23 pm
unofficial solution
-----------------------------------
since its a Stage1 problem, using turing is allowed. Here's a solution I came up with using Turing.
Basically its the same solution, but transfered into turing syntax. See file attached.
Note:
if you're going to run the solution, make sure to create a file called data.in in same folder and fill it with atleast 1 integer number. Program output will be saved in file called data.out which you don't have to create.