1996 Canadian Computing Competition, Stage 1

Problem A: Deficient, Perfect, and Abundant

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


Sample Output

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

All Submissions
Best Solutions

Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 28, 2008

Problem Types: [Show]

Languages Allowed:

Comments (Search)

Can someone please check my code and tell me whats is wrong with it?
In details, it is showing my output for 28 is a perfect number but 28 is a perfect number, right? Thanks.

In the Guidelines for submitting, we explicitly recommend against storing all outputs for the end.

Your code has a simple logic error. You should test your code on multiple inputs to make sure they're correct.

Do note that you won't be able to see all of your output, so your code is being tested on more than just the number 28.

Thanks @jargon. Without storing inputs and outputs life is simple :).
Also I fixed my bug from earlier code.

Sorry I totally forgot about that my bad.

So I need help with this, I think I know the problem but I don't know how to implement it.

Don't post your code here! If you do, people who HAVEN'T solved the question might copy it. If you just ask for help, Only people who SOLVED the problem can view your submission and help you. For starters, just edit your comment and delete the code.

Sorry but I really don't get the meaning of "The input starts with the number of integers that follow", the format of input confuses me. Is it a continuous series of input numbers, or separated?

Personally I feel the sample should make this clear, but let me reword it for you.

The first line of the input will contain a number T, the number of test cases.

Each of the following T lines will contain a positive integer n, 1 < n < 32500.

For each integer n, determine whether it is deficient, perfect, or abundant.

Oh thx! I didn't expect to be replied so fast :D Now I get it

I have tried running the program on my own multiple times, and the compiler never complained. Can I please be told why the judge doesn't accept it?
I apologize if it's something that had already been outlined in help.

You have misinterpreted the input format. Your output does not currently match the sample case exactly.

Here are the first two lines of your exception. The last line would help you more, but you should be able to figure it out with this.
Exception in thread "main" java.util.NoSuchElementException 
at java.util.Scanner.throwFor(Scanner.java:907)

I'm fairly certain my algorithm is correct but the judge keeps on failing me on the 30000 test case (i already did this in pascal with pretty much the same algorithm). At first I thought it was the range so i put it up to long int, but it still did not work, I even added one to it and it still got wrong (it was perfect number, added one and it was still perfect number).

Is this a known bug or did i get my algorithim wrong?

Does your code work on the 30000 test case on your own computer? ;)

Well, I just submitted this one... And the thing is that it is saying my answer for one of them is wrong. But I believe that is wrong. Could someone maybe check it? Thank you!

Carefully compare your output with the sample testcase. It has to be the exact same.

I still cannot figure it out. What I am outputting seems like the exact same as how it says it has to be on the question. But I guess I will take a look at it a bit later since I can't find it now. Thank you!

*hint* grammar rules >:P

Wow. LOL, thanks, I got it now :P

i want to know aht i am getting wrong

Read the sample output very carefully.

it said less than 32500 so i thought integers were allowed....mad.gif

The number is less than 32500, but the sum of its divisors might not be. (The case you failed was 30000, for example)

Not to be overly 'answer checking' but i tried this multiple times on TP and they work fine but i dont get the problem here...I dont think its a typo either...

Didn't you see this?
Pascal users: make sure you're using longints, if necessary.
In general you should always use longint instead of integer.