A Plus B (Hard)

View as PDF

Submit solution


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 2^{64}. In fact, he will give problems involving addition of 100\,000-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 N, the number of addition problems Xyene needs to do. The next N lines will each contain two space-separated integers with up to 100\,000 digits in decimal, the two integers Xyene needs to add. N will never be greater than 50.

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

Output Specification

Output N 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

Comments


  • 0
    Jeffmagma
     commented on Oct. 19, 2017

    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


    • 1
      Injust
       commented on Oct. 20, 2017

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


  • 1
    Master_Bob
     commented on Oct. 2, 2017 edited

    Never mind I fixed it


  • 0
    Beautiful_Times
     commented on Oct. 2, 2017

    Can we enable turing for this question?


    • 0
      Xyene
       commented on Oct. 2, 2017

      Done, good luck!


  • 0
    1yangdan
     commented on Sept. 30, 2017

    Compilation Error. I submitted too many times


  • 1
    Ninjaclasher
     commented on Sept. 19, 2017

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


    • 2
      aeternalis1
       commented on Sept. 19, 2017

      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.


      • 1
        Ninjaclasher
         commented on Sept. 20, 2017

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


  • 0
    aeternalis1
     commented on Sept. 15, 2017

    Can the two integers have leading zeros?


    • -1
      Pleedoh
       commented on Sept. 15, 2017

      No


  • 0
    pro
     commented on Aug. 17, 2017

    do we convert it to string first?


  • -1
    RourisGaSuki
     commented on March 30, 2017

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


    • 2
      Xyene
       commented on March 30, 2017

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


  • -10
    trollakatroll
     commented on Jan. 21, 2017
    time limit exceeded ???

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

    anybody know why???


    • 15
      Xyene
       commented on Jan. 21, 2017 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?


  • 9
    Xyene
     commented on Aug. 28, 2016 edited
    Java is now allowed

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


    • 0
      max
       commented on Oct. 8, 2017 edited

      Thanks!


  • 4
    Kirito
     commented on July 27, 2016
    Add Turing?

    Cuz it can't even handle 2^64.


  • -21
    sinxcosx
     commented on Oct. 26, 2015
    Why no JAVA?!

    Why can't we use java?


    • 3
      Kirito
       commented on April 15, 2016

      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?


      • 1
        Xyene
         commented on April 15, 2016 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.


    • 0
      acetao
       commented on Dec. 12, 2015

      Use Java?It's to simple.


    • -1
      sigengliu
       commented on Nov. 24, 2015

      too young too simple sometimes naive


    • 3
      fafalnq
       commented on Oct. 30, 2015

      Welcome to reality my friend


  • -9
    BMP
     commented on Nov. 29, 2014
    Can you guys add Java to this please.

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


    • 6
      FatalEagle
       commented on Nov. 29, 2014

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


      • -5
        Yuting9
         commented on Nov. 29, 2014

        It is pretty hard...


        • -7
          BMP
           commented on Nov. 29, 2014

          he refers to Big Integers


      • -7
        BMP
         commented on Nov. 29, 2014

        Awww :(