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

3
4
6
12

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:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

<
1
2
>

Though I check the comments that share the same error about the number 28, I cannot understand my potential logic error on my code.Can somebody help me out?

Hint: Your code isn't wrong about 28.

Can anyone look over my code and tell me what's the problem? Thank you

i suggest u put sum = 0 instead of sum = 1 each time u did that, and check for any grammar error in both the code and output

Hi I fixed all the grammar error and now I got 5/5! Thank you so much!


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.

Hi, I;m getting the same problem as JamesBond, but I don't understand the solution jargon has given. Or perhaps i have a different error in my code? Could someone please help me.

yep, you need to reset your sum, i tried your code with reseted sum and it works:) :p, there's your problem

Thanks for your help @magicalsoup! The reset did work.

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.

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)