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
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
2
12345678901234567900
10
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.
10
The number 10 is not divisible by 11.
Comments
I'm at a loss for why this doesn't work. The one example seems to work perfectly, and if I manually validate what it's reporting in the WA output, I'm generating what I'd expect it to output. I must just be missing something (and yes, I've tried it with both one and two carriage returns at the end of the final statement, both fail). Can someone please point out what my mistake is: https://dmoj.ca/src/6759637? Thanks!
Your program needs to support 50 digit integers.
uint64_t
doesn't support integers longer than 20 digits.Why am I getting OLE?
Can someone take a look at my code? I'm not sure why it's not working...
You have to print only 1 newline at the end.
how do you fix Presentation Error, check your whitespace?
EDIT: you need only need one \n for the last output
Could someone please look at my last submission? I don't know what causes the WAs... Thanks
Nvm I got it...The question should clarify that, if not divisible by 11, output "The number xxx is NOT divisible by 11."
Could someone check my most recent submission? It ACs on the first test case but not on the next two, and I can't figure out why not. Any help would be appreciated!
EDIT: forgot to check the final 2 digit number (ex. 22) lmao
Still cannot figure out what is the problem with my code -.- Can someone give me some hints as to what exactly I am doing wrong.
you have to print the number again, so if the number was 121, you have to print
not
which is what you are doing.
THANKS SO MUCH! That was my problem too.
My mistake, I really should read questions carefully. Thank you very much!
This is a bit (a lot) harder because the input number is so long you can't put it all in one big
int
orlong
; the code will throw anInputMismatchException
The memory limit is also super low
Never mind this because the problem was edited some 22 years ago
DAMN
I forgot "."
......
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?
String, byte array, int array, char array, etc
You could always look into how
BigInteger
works internally. Besides, allowingBigInteger
would be unfair to languages that don't have it, and would also defeat the purpose of the question.thanks alot :)
Just wondering, why is there no Python 3 in the allowed languages?
Allowing Python would make the problem trivial because of Python's support of arbitrarily big numbers.
Oh, right.
uh, java.lang.NumberFormatException?
(much larger than what can fit in even a long)
0-50+ digits works on my computer? w/o errors?
My bad, I assumed that would be your issue without reading your code. Try a number like
848098180322800092606233221468227354577849547220
.Hm, all the big numbers work in my code but I keep getting that NumberFormatError, any tips?
Try numbers:
54862354760000000000532645 10000000000500000000007
I did it bois. Thank you!
This comment is hidden due to too much negative feedback. Show it anyway.
What's the exact text to output if the number is not divisible by 11? "The number ____ is not divisible by 11."?
Yes.