02. 멀쩡한 사각형
코딩테스트 연습 > Summer,Winter Coding(2019) > 멀쩡한 사각형
https://programmers.co.kr/learn/courses/30/lessons/62048
Input value =
Process =
Output value =
#00
W,H = 8,12
#01-1 GCD를 이용
def gcd(a,b):
return b if a==0 else gcd(b%a, a)
W*H-(W+H)+gcd(W,H)
#01-2 오름차순,내림차순 이용
from math import floor, ceil
result = 0
if W==H:
result = (H-1)*W
elif W==1 or H==1:
result = 0
else:
for i in range(1,W):
result += (floor(i*H/W)+H-ceil(i*H/W))
result
from math import gcd
def solution(W,H):
return W*H-(W+H)+gcd(W,H)
# Code test
W,H = 8,12
solution(W,H)
def gcd(a,b):
return b if a==0 else gcd(b%a,a)
def solution(W,H):
return W*H-(W+H)+gcd(W,H)
# Code test
W,H = 8,12
solution(W,H)
from math import floor, ceil
def solution(W,H):
square = 0
if W==H:
return (H-1)*W
elif W==1 or H==1:
return 0
else:
for i in range(1,W):
square += (floor(i*H/W)+H-ceil(i*H/W))
return square
# Code test
W,H = 8,12
solution(W,H)