[백준/파이썬] 16306번 풀이

업데이트:



문제 정보


풀이

문제

Fidget spinners are so 2017; this years’ rage are fidget cubes. A fidget cube is a cube with unit side lengths, which you hold in your hand and fidget with. Kids these days, right?

You work in the planning department for a company that creates and ships fidget cubes. Having done some market analysis, you found that your customers want to receive shipments of exactly V fidget cubes.

This means you have to design a container that will hold exactly V fidget cubes. Since fidget cubes are very fragile, you cannot have any empty space in your container. …

입력 요약
The input contains a single integer, 1 ≤ V ≤ 106, the number of fidget cubes for which you need to build a box.

출력 요약
Print the cost of the cheapest rectangular box as specified in the statement.

코드

v=int(input())
m=10**6*6
l=[]
for i in range(1,int(v**.5)+1):
    if v%i==0:
        l.append(i)
        if i*i!=v:l.append(v//i)
for a in l:
    for b in l:
        if v%(a*b)!=0:continue
        c=v//(a*b)
        m=min(m,(a*b+b*c+c*a)*2)
print(m)

설명

핵심은 구현 관점에서 Fidget spinners are so 2017; this years’ rage are fidget cubes. A fidget cube is a cube with unit side lengths, which you hold in your hand and fidget …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기