-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0629_square.py
More file actions
47 lines (34 loc) · 736 Bytes
/
Copy path0629_square.py
File metadata and controls
47 lines (34 loc) · 736 Bytes
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
45
46
47
from math import ceil, trunc
def solution(w, h):
answer = w * h
i = 0
r = w / h
temp=0
if w>h:
temp =w
w=h
h=temp
while (True):
temp += ceil(r*(i+1))-trunc(r*i)
if(int((i+1) * r) == (i+1) * r):
break
i += 1
return int(answer - temp *h/(i+1))
from math import gcd
def solution(w, h):
answer = w * h
temp=0
GCD=gcd(w,h)
if w>h:
temp =w
w=h
h=temp
temp=0
r = w / h
for i in range(GCD-1):
if (int((i+1) * r) != (i+1) * r) and (int((i) * r) != (i) * r):
temp += 2
else:
temp += 1
return int(answer - temp * h / (i+1))
print(solution(8,12))