Problems with A+B problem

Revision en2, by fakeofakeov, 2020-11-21 22:30:29

Last week I found a difficult problem. In standard input there are two numbers A and B. I need to output sum A + B. I solve this problem

A, B = map(int, input().split())
ANS = 0
for i in range(A):
    ANS += 1
for i in range(B):
    ANS += 1
print(ANS)

But then I found more difficult problem. In this problem A can be < 0. Please help me with this difficult problem. upd: Now I know how to solve this problem, but it works very slow. I have heard about solution O(B). Does anybody know it?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English fakeofakeov 2020-11-21 22:30:29 124
en1 English fakeofakeov 2020-11-21 22:09:27 418 Initial revision (published)