fakeofakeov's blog

By fakeofakeov, history, 3 years ago, In English

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?

  • Vote: I like it
  • -19
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

if A<0 then add -1 xD