-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbombs.py
executable file
·44 lines (35 loc) · 913 Bytes
/
bombs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/local/bin/python2
def solution(M,F):
gen = 0
m = int(M)
f = int(F)
while(True):
if m <= 0 or f <= 0:
return "impossible"
if m == 1 and f > 1:
return str(gen + f - 1)
if f == 1 and m > 1:
return str(gen + m - 1)
if m > f:
n = m/f
if n > 0:
m = m-n*f
gen = gen + n
else:
m = m-f
gen = gen + 1
elif m < f:
n = f/m
if n > 0:
f = f-n*m
gen = gen + n
else:
f = f-m
gen = gen + 1
else:
if m == 1 and f == 1:
return str(gen)
else:
return "impossible"
return str(gen)
print solution('100000000000000000000000000000000000000000000000000', '7')