## CCC '96 S2 - Divisibility by 11

View as PDF

Points: 7
Time limit: 2.0s
Memory limit: 16M

Problem type
Allowed languages
Assembly, C, C++, COBOL, Fortran, Java, Pascal, Prolog, Text

Write a program which accepts as input a positive integer and checks, using the algorithm described below, to see whether or not the integer is divisible by 11. This particular test for divisibility by 11 was given in 1897 by Charles L. Dodgson (Lewis Carroll).

Algorithm:
As long as the number being tested has more than two digits, form a new number by:
• deleting the units digit
• subtracting the deleted digit from the shortened number
The remaining number is divisible by 11 if and only if the original number is divisible by 11.
Note:
Leading zeroes are not considered part of the number and should not be printed.

As usual, the first number in the input indicates the number of positive integers that follow. Each positive integer has a maximum of 50 digits. You may assume no leading zeroes exist in the positive integers.

For each positive integer in the input, the output consists of a series of numbers formed as a digit is deleted and subtracted, followed by a message indicating whether or not the original number is divisible by 11. Outputs for different positive integers are separated by blank lines.

#### Sample Input

1
12345678901234567900

#### Sample Output

12345678901234567900
1234567890123456790
123456789012345679
12345678901234558
1234567890123447
123456789012337
12345678901226
1234567890116
123456789005
12345678895
1234567884
123456784
12345674
1234563
123453
12342
1232
121
11
The number 12345678901234567900 is divisible by 11.

• Gabrieltian  commented on Oct. 1, 2018, 7:25 p.m.

maybe double for java

• def_d  commented on Aug. 23, 2018, 6:28 p.m. edit 4

This is a bit (a lot) harder because the input number is so long you can't put it all in one big int or long; the code will throw an InputMismatchException

The memory limit is also super low

Never mind this because the problem was edited some 22 years ago

• Inyj  commented on June 29, 2018, 12:40 p.m. edit 5

• 1419903188  commented on Oct. 13, 2017, 5:57 p.m.

DAMN

I forgot "."

......

• trollakatroll  commented on Jan. 21, 2017, 10:59 a.m.

i have to say i have some concerns about your requirements and because of that it has caused me to fail many times. you should explain just a bit more and it would be a lot clearer.

• trollakatroll  commented on Jan. 19, 2017, 5:19 p.m.

this question doesnt allow us to use bigdecimal or biginteger. how else are we supposed to hold such a big number? or can you allow to use bigdecimal or biginteger?

• TypicalToxic  commented on Jan. 20, 2017, 2:17 p.m.

String, byte array, int array, char array, etc

• Kirito  commented on Jan. 19, 2017, 5:49 p.m.

You could always look into how BigInteger works internally. Besides, allowing BigInteger would be unfair to languages that don't have it, and would also defeat the purpose of the question.

• paydayzcool  commented on Oct. 19, 2016, 8:29 a.m.

Just wondering, why is there no Python 3 in the allowed languages?

• nathanl3  commented on Oct. 19, 2016, 8:45 a.m.

Allowing Python would make the problem trivial because of Python's support of arbitrarily big numbers.

• paydayzcool  commented on Oct. 19, 2016, 11:26 p.m.

Oh, right.

• TypicalToxic  commented on Sept. 12, 2016, 8:10 p.m.

uh, java.lang.NumberFormatException?

• Xyene  commented on Sept. 12, 2016, 8:11 p.m.

Each positive integer has a maximum of 50 digits.

(much larger than what can fit in even a long)

• TypicalToxic  commented on Sept. 12, 2016, 8:14 p.m.

0-50+ digits works on my computer? w/o errors?

• Xyene  commented on Sept. 12, 2016, 8:22 p.m.

My bad, I assumed that would be your issue without reading your code. Try a number like 848098180322800092606233221468227354577849547220.

• BMP  commented on Dec. 20, 2016, 12:17 p.m.

Hm, all the big numbers work in my code but I keep getting that NumberFormatError, any tips?

• TypicalToxic  commented on Dec. 20, 2016, 9:10 p.m.

Try numbers:

54862354760000000000532645 10000000000500000000007

• TypicalToxic  commented on Sept. 12, 2016, 9:36 p.m.

I did it bois. Thank you!

• Kirito  commented on Sept. 5, 2016, 2:54 p.m.

New testcases were added, and all submissions have been rejudged.

• nathanl3  commented on Sept. 2, 2016, 7:51 p.m.

What's the exact text to output if the number is not divisible by 11? "The number ____ is not divisible by 11."?

• Kirito  commented on Sept. 2, 2016, 8:11 p.m.

Yes.