## A Plus B (Hard)

View as PDF

Points: 15 (partial)
Time limit: 5.0s
Memory limit: 64M

Problem type

Allowed languages
Assembly , C , C++ , COBOL , Forth , Fortran , Java , Lua , Pascal , Prolog , Text , Turing

Xyene's teacher realized that he was cheating, and was using the code you wrote to save his marks. So, the math teacher decided that he will mess up your program by using numbers larger than . In fact, he will give problems involving addition of -digit numbers as punishment. However, Xyene is once again on top — he has promised you a "reward" if you help him again. You suspect it might not be anything more than 15 points, but you still have your hopes up...

#### Input Specification

The first line will contain an integer , the number of addition problems Xyene needs to do. The next lines will each contain two space-separated integers with up to digits in decimal, the two integers Xyene needs to add. will never be greater than .

Warning: The test cases are a lot more sadistic than the sample.

#### Output Specification

Output lines, the solutions to the addition problems in order.

#### Sample Input

4
1 1
226077045628835347875 -572260769919042128358
-803119834418378628674 236083700054616110639
-435599336891761067707 451767479989987922363

#### Sample Output

2
-346183724290206780483
-567036134363762518035
16168143098226854656

• DerekZhang  commented on Dec. 24, 2017, 12:17 a.m.

Not sure why I'm WA on two cases. On case #2, the input is 7808787 -2084742, and it WA because it's outputting 5403285 (wrong), but when I run the same input locally, it outputs 5724045 (right). I have no idea why this is happening. I thought it was because some variables weren't being reset, but all of the variables used in calculations are local. Any ideas?

• neo752  commented on Nov. 24, 2017, 10:51 a.m.

Why is my code out of range? I don't really understand it.

• SBOUIFERS  commented on Oct. 29, 2017, 8:53 a.m.

hello please big integer in c = double

• wleung_bvg  commented on Oct. 29, 2017, 9:47 a.m.

Unfortunately, using a double is not sufficient enough (nor accurate enough) to store a 100000 digit number. Try finding another way you can store the digits (it may involve creating your own data structure).

• Ninjaclasher  commented on Oct. 29, 2017, 10:19 a.m.

cough cough string cough cough

• BonyBen  commented on Nov. 14, 2017, 11:13 p.m.

rood

• rsylshzxdkh  commented on Oct. 21, 2017, 2:55 p.m.

Can someone tell me what I'm doing wrong? Or at least give a case to test?

• TypicalToxic  commented on Oct. 22, 2017, 5:25 p.m.

try

99 99 -99 99 99 -99 100 99 -100 99 100 -99

• Jeffmagma  commented on Oct. 19, 2017, 10:26 p.m.

Can someone give a hint as to why my submission isn't passing? I've tried many of my own test cases (up to 100,000 characters) and they all passed on my side

• Injust  commented on Oct. 20, 2017, 12:21 a.m.

Might need a wee bit more testing, 2 + 10 isn't 3 :(

• Jeffmagma  commented on Oct. 20, 2017, 7:16 p.m.

damn thanks lol, apparently i misinterpreted how string::operator> worked

• Beautiful_Times  commented on Oct. 2, 2017, 10:50 p.m.

Can we enable turing for this question?

• Xyene  commented on Oct. 2, 2017, 11:58 p.m.

Done, good luck!

• Ninjaclasher  commented on Sept. 19, 2017, 9:01 p.m.

Code is correct, output compares correctly, still WAs. Anyone have any idea why?

• aeternalis1  commented on Sept. 19, 2017, 10:20 p.m.

If you look at your output for test case 6 (on your most recent submission), there is a leading zero after the negative. Get rid of that.

• Ninjaclasher  commented on Sept. 20, 2017, 12:06 p.m.

Fixed that, but there's still something wrong with the output..... Any suggestions?

• aeternalis1  commented on Sept. 15, 2017, 8:07 a.m.

Can the two integers have leading zeros?

• Pleedoh  commented on Sept. 15, 2017, 11:06 a.m.

No

• pro  commented on Aug. 17, 2017, 8:58 p.m.

do we convert it to string first?

• RourisGaSuki  commented on March 30, 2017, 11:16 a.m.

But why isn't python2 and lua allowed :v(

• Xyene  commented on March 30, 2017, 1:01 p.m.

The difficulty of this in Python is the same as the regular aplusb (i.e. not worth 15 points). I've enabled Lua.

• trollakatroll  commented on Jan. 21, 2017, 6:15 p.m.
time limit exceeded ???

my machine took few milliseconds to progress and your machine said it took more than 5 seconds

anybody know why???

• Xyene  commented on Jan. 21, 2017, 7:00 p.m. edited

Because copy/pasting code from Java's BigInteger implementation was never intended as a correct solution to this problem. BigInteger is explicitly disallowed, so why would copypasta of it be any different?

• Xyene  commented on Aug. 28, 2016, 5:36 p.m. edited
Java is now allowed

Java is now allowed for this problem, though use of the BigInteger and BigDecimal classes is disallowed.

• max  commented on Oct. 8, 2017, 5:39 a.m. edited

Thanks!

• Kirito  commented on July 27, 2016, 7:15 p.m.

Cuz it can't even handle 2^64.

• sinxcosx  commented on Oct. 26, 2015, 10:29 p.m.
Why no JAVA?!

Why can't we use java?

• Kirito  commented on April 15, 2016, 12:53 a.m.

Judging by the GitHub page, Java could soon be allowed for this question, just with BigIntegers disabled.

P.S. Xyene, you're also going to disable BigDecimal...right?

• Xyene  commented on April 15, 2016, 1:13 p.m. edited

Yes, BigDecimal would be disabled. Support for disallowing big math is implemented judge-side, but it will likely be a while before we get to adding any kind of support for it on the site.

• acetao  commented on Dec. 12, 2015, 5:10 a.m.

Use Java？It's to simple.

• sigengliu  commented on Nov. 24, 2015, 12:13 p.m.

too young too simple sometimes naive

• fafalnq  commented on Oct. 30, 2015, 11:32 a.m.

Welcome to reality my friend

• arock  commented on Oct. 27, 2015, 2:59 p.m.
• BMP  commented on Nov. 29, 2014, 7:19 p.m.

And please don't beef me, I need them 15 points.

• FatalEagle  commented on Nov. 29, 2014, 7:35 p.m.

The difficulty of this in Java is the same as the regular aplusb (i.e. not worth 15 points).

• Yuting9  commented on Nov. 29, 2014, 7:52 p.m.

It is pretty hard...

• BMP  commented on Nov. 29, 2014, 8:05 p.m.

he refers to Big Integers

• BMP  commented on Nov. 29, 2014, 7:41 p.m.

Awww :(