Skip to content

Commit 4cff09b

Browse files
authored
Add solution for ADD
1 parent 61b7a4c commit 4cff09b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Python/add.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
input_numbers = input().split(" ")
2+
a,b = int(input_numbers[0]), int(input_numbers[1])
3+
def getSum(a: int, b: int) -> int:
4+
mask = 0xffffffff
5+
while b&mask:
6+
a, b = a^b, (a&b)<<1
7+
8+
max_int = 2**(32-1) - 1
9+
if b < max_int:
10+
return a
11+
else:
12+
# if there is overflow
13+
# i.e if a is a negative value.
14+
return a& mask
15+
print(getSum(a,b))

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ In the "Repository" you will find the topics and its problems.
172172

173173
| # | Title | Solution |
174174
| --- | ---------------------------------------------------------------------------------------- | ------------------------------ |
175-
| 01 | [Add](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/A) |
175+
| 01 | [Add](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/A) | [Python](./Python/add.py) |
176176
| 02 | [PRINT](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/B) |
177177
| 03 | [Different functions](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/C) |
178178
| 04 | [prime function](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/D) |

0 commit comments

Comments
 (0)